On Mon, Jan 2, 2012 at 10:49 PM, Linus P. < [email protected]> wrote:
Hi!
In Rails 3.1 there is only one method for migrations called ‘change’.
Not exaclty. up and down still exist (but now instance methods instead
of
class methods).
Google (“rails guide migrations”).
I want to run some code in a migration only when migrating up, not down.
Is that possible?
Yes.
And what about:
def up
AdminUser.create!(:email => '[email protected]
', :password => ‘password’, :password_confirmation => ‘password’)
end
def down
u = AdminUser.find_by_email(‘[email protected]’)
u.destroy
end
Any ideas?
If the down migration is really impossible to do (which can happen;
e.g because you miss data to reset everything to the original state)
than you can raise ActiveRecord::IrreversibleMigration exception
in the down migration.