rails migration version compatibility -


here scenario

production/staging code on version x

version x of code

# order model class order < activerecord::base   has_many :payment_transactions   # has column check_number    def update_report     reporttable.where(:order_id => id).first.update_attributes(:check_number => check_number)   end end  # payment_transaction model class paymenttransaction < activerecord::base  end 

version x + 5 of code

# migration order.all.map{|x| x.update_report } 

version x + 10 of code (current)

# migration add_column :payment_transactions, :check_number, :integer  # order model class order < activerecord::base   has_many :payment_transactions   # moved column check_number payment_transactions    def check_number     self.payment_transactions.where(:method => 'check').blank? ? nil : self.payment_transactions.where(:method => 'check').first.check_number   end    def update_report     reporttable.where(:order_id => id).first.update_attributes(:check_number => check_number)   end end  # payment_transaction model class paymenttransaction < activerecord::base   # has column check_number end 

now when update code on staging environment latest version (x+10) , run migration, migration on x+5 fails because tries run this

def check_number   self.payment_transactions.where(:method => 'check').blank? ? nil : self.payment_transactions.where(:method => 'check').first.check_number end 

and payment_transaction not check_number field until x+10 migration.

whats best way handle this?

i comment update_report call on x+5 migration, run it, run snippet on rails console after i'm done.

or change migration perform direct sql query:

execute "update report_tables set check_number = x.check_number ...." 

Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -