# Reverting plugin migrations

**URL:** <https://www.ruby-forum.com/t/reverting-plugin-migrations/131009>\
**Category:** Engines Development\
**Created:** [March 5, 2008, 5:15am UTC](https://www.ruby-forum.com/t/reverting-plugin-migrations/131009 "2008-03-05T05:15:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 5, 2008, 5:15am UTC](https://www.ruby-forum.com/t/reverting-plugin-migrations/131009/1 "2008-03-05T05:15:46Z")

</div>

Hi all,  
I’ve added quite a bit of default data population to a migration  
script on  
an engine I’m working on. When I try to revert to a previous version,  
it  
doesn’t work as I expected it to. With rails app migrations I can do  
“rake  
db:migrate VERSION=0” to drop all the tables. When I run “rake  
db:migrate\_plugins VERSION=0”, I can’t roll back the migration, so I’m  
unable to test my updated migration script. I tried deleting the table,  
but  
now I’m stuck, I can’t re-create my table with migrations. Any advice?

Thanks,  
Todd

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 5, 2008, 9:06am UTC](https://www.ruby-forum.com/t/reverting-plugin-migrations/131009/2 "2008-03-05T09:06:58Z")

</div>

What error (if any) do you see? Is there any reason you’re using the  
db:migrate\_plugins task rather than script/generate plugin\_migration?

On 5 Mar 2008, at 04:15, “Todd N.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 5, 2008, 7:40pm UTC](https://www.ruby-forum.com/t/reverting-plugin-migrations/131009/3 "2008-03-05T19:40:06Z")

</div>

I was assuming that I was using a deprecated methodology from an old  
tutorial and that “rake db:migrate\_plugins” was the correct way to run  
the  
migration of an engine. Since I know now its not, I’m still stumped as  
to  
why this doesn’t work. When I use “script/generate plugin\_migration”,  
it  
generates the file 087\_project\_rank\_to\_version\_1.rb, which in turn runs  
the  
migration for the “project\_rank” plugin. However if I do the following

rake db:migrate VERSION=86

it doesn’t drop my table, and my code for my single migration in my  
plugin  
is

def self.down  
drop\_table :project\_ranks  
end

I don’t understand why its not dropping the table, I don’t receive an  
error,  
even in verbose mode, but nothing happens with the table, it just  
outputs  
that its being reverted. If I manually delete the table, then run

rake db:migrate

after rolling back to version 86, I would expect it to create the table.  
However, it does not create the table, and it doesn’t give me any  
warnings.  
It just displays a message that my plugin has been migrated. I thought  
my  
migration was pretty straight forward, but it just doesn’t work. Has  
anyone  
else had this problem? I’ve included my migration script below in case  
I’ve  
done something wrong I’m missing.

Thanks,  
Todd

class CreateProjectRankTable \< ActiveRecord::Migration  
def self.up  
create\_table :project\_ranks, :force =\> true do |t|  
t.column “rank”, :integer  
t.column “project\_id”, :integer  
end

```
add_index "project_ranks", ["project_id"], :name =>

```

“project\_ranks\_project\_id”  
add\_index “project\_ranks”, [“rank”], :name =\> “project\_ranks\_rank”

end

def self.down  
drop\_table :project\_ranks  
end  
end

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 5, 2008, 9:36pm UTC](https://www.ruby-forum.com/t/reverting-plugin-migrations/131009/4 "2008-03-05T21:36:59Z")

</div>

class ProjectRankToVersion1 \< ActiveRecord::Migration  
def self.up  
Rails.plugins[“project\_rank”].migrate(1)  
end

def self.down  
Rails.plugins[“project\_rank”].migrate(2)  
end  
end

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 5, 2008, 9:00pm UTC](https://www.ruby-forum.com/t/reverting-plugin-migrations/131009/5 "2008-03-05T21:00:59Z")

</div>

Can you send the contents of migration 87?

Thanks,

James

On 5 Mar 2008, at 18:39, “Todd N.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 5, 2008, 10:45pm UTC](https://www.ruby-forum.com/t/reverting-plugin-migrations/131009/6 "2008-03-05T22:45:04Z")

</div>

That got it James, thanks for the help! Here’s what I did specifically.

1. Deleted the row from plugin\_schema\_info that contained my plugin
2. Deleted the application migration that was created, file  
087\_project\_rank\_to\_version\_1.rb
3. re-ran “script/generate plugin\_migration”
4. ran “rake db:migrate VERSION=86”
5. ran “rake db:migrate”

Thanks for all your help. As a RoR and Engines noob, I really  
appreciate  
it!

Todd

---

<div class="post-metadata">

**Author:** ![elemental](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/6de8d8/32.png) [@elemental](https://www.ruby-forum.com/u/elemental)\
**Post date:** [March 5, 2008, 10:26pm UTC](https://www.ruby-forum.com/t/reverting-plugin-migrations/131009/7 "2008-03-05T22:26:11Z")

</div>

On 05/03/2008, Todd N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> class ProjectRankToVersion1 \< ActiveRecord::Migration  
> def self.up  
> Rails.plugins[“project\_rank”].migrate(1)  
> end
> 
> def self.down  
> Rails.plugins[“project\_rank”].migrate(2)  
> end  
> end

OK - so it looks like the plugin\_migration generator thinks your  
“project\_rank” plugin is currently at version 2 (which is why the  
‘down’ migration is trying to go to that version), but the latest  
migration file it can actually find would take it to version 1.

Can you look at the contents of the plugin\_schema table? Is there any  
way that the version for that plugin could’ve been set to 2 at some  
point in the past?

Since this project sounds like it’s just starting, you should be able  
to reset the value in the database to “0”, and change the version in  
the generated down method by hand. Hopefully that should sort it out.

James
