Reverting plugin migrations

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

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.” [email protected]

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

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

Can you send the contents of migration 87?

Thanks,

James

On 5 Mar 2008, at 18:39, “Todd N.” [email protected]

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

On 05/03/2008, Todd N. [email protected] 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