Note that there are some explanatory texts on larger screens.

plurals
  1. POrails migration version compatibility
    text
    copied!<p>Here is the scenario</p> <p>production/staging code is on version X</p> <p>Version X of code</p> <pre><code># order model class Order &lt; ActiveRecord::Base has_many :payment_transactions # has column for check_number def update_report ReportTable.where(:order_id =&gt; id).first.update_attributes(:check_number =&gt; check_number) end end # payment_transaction model class PaymentTransaction &lt; ActiveRecord::Base end </code></pre> <p>Version X + 5 of code</p> <pre><code># migration Order.all.map{|x| x.update_report } </code></pre> <p>Version X + 10 of code (current)</p> <pre><code># migration add_column :payment_transactions, :check_number, :integer # order model class Order &lt; ActiveRecord::Base has_many :payment_transactions # moved the column check_number to payment_transactions def check_number self.payment_transactions.where(:method =&gt; 'check').blank? ? nil : self.payment_transactions.where(:method =&gt; 'check').first.check_number end def update_report ReportTable.where(:order_id =&gt; id).first.update_attributes(:check_number =&gt; check_number) end end # payment_transaction model class PaymentTransaction &lt; ActiveRecord::Base # has column for check_number end </code></pre> <p>Now when i update the code on staging environment to the latest version (X+10) and run migration, the migration on X+5 fails because it tries to run this</p> <pre><code>def check_number self.payment_transactions.where(:method =&gt; 'check').blank? ? nil : self.payment_transactions.where(:method =&gt; 'check').first.check_number end </code></pre> <p>and payment_transaction will not get check_number field until X+10 migration. </p> <p>Whats the best way to handle this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload