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 :) thanks, roupen n. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Feb 14, 2008 at 1:59 PM, nahabed <roupenn-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 :)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. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Makes sense - thanks! On Feb 14, 2:02 pm, "Rick DeNatale" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Thu, Feb 14, 2008 at 1:59 PM, nahabed <roup...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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 :) > > 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. > > -- > Rick DeNatale > > My blog on Rubyhttp://talklikeaduck.denhaven2.com/--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---