Close
Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

LABS
Reversible migrations in Rails 3.1+

In Rails 3.1 and newer, when you write a migration by hand, you can (usually) just define a change method instead of an up and a down method.

This StackOverflow answer from user Readonly demonstrates the use of change nicely:

class RenameOldTableToNewTable< ActiveRecord:Migration
  def self.up
    rename_table :old_table_name, :new_table_name
  end
  def self.down
    rename_table :new_table_name, :old_table_name
  end
end

becomes

class RenameOldTableToNewTable< ActiveRecord:Migration
  def change
     rename_table :old_table_name, :new_table_name
  end
end

Comments
Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *