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
About the Author