How do I reuse a previous migration's up or down methods
I had created my own User class and authentication from scratch but have recently decided to scrap it and start over using the Devise gem. So before I leverage the Devise migrations I need to create a migration to kill off my User table. "Easy", I thought, "I'll just use the down method of the migra开发者_运维技巧tion that created my User table". But I can't for the life of me work out how to reference that from a new migration. Thoughts?
If your user migration has anything outside of just dropping the user table I'm not too sure, but you can edit devise's migration and add the force = true option.
class DeviseCreateUsers < ActiveRecord::Migration
def self.up
create_table(:users, :force => true) do |t|
...
end
end
end
This will make it so that if your user table exists, it'll be dropped before hand.
You can just manually drop it:
class DropUsers < ActiveRecord::Migration
def self.up
drop_table :users
end
def self.down
raise ActiveRecord::IrreversibleMigration
end
end
精彩评论