migrate roll back...

Say I table called products with 001_create_products.rb Then say I add
a column called price to product using a the migration
002_add_price.rb

002_add_price.rb
class AddPrice < ActiveRecord::Migration
  def self.up
     add_column ...
  end

def self.down
  remove_column ...
end

Now if I decide to remove the price column, effectively, rolling BACK
my migration to 001 - how does "self.down" in 002_add_price.rb get
called? I'm puzzled :slight_smile:

thanks, roupen n.

Pretty much the same way the self.up got run going the other way.

Basically rake db:migrate uses the VERSION environment variable to
determine which migration level is desired. It then looks at the
schema_version in the db to determine the current version. If
schema_version is less than VERSION, then it looks for migrations >
schema_version and <= VERSION loads each one in ascending sequence and
executes the up method in each migration.

Similarly if schema_version is > than VERSION it runs the migrations
in descending sequence and executes the down method in each one.

db:rollback works basically the same way.

Makes sense - thanks!