When, you are coding data migrations, and decide to use model classes in your migrations. You are asking for trouble. Why?
Because, migrations is a fluid thing, and say you have decided to get rid of your model all together,then your migrations would magically start failing. This could be a problem.
Toolamantim, suggests an alternative. Simply redefine your models inside migrations itself:
# class Product < ActiveRecord::Base; end # class SoftwareProduct < Product; end # class CourseProduct < Product; end # # def self.up # add_column :products, :position, :integer # Product.reset_column_information # # # Set default list orders # SoftwareProduct.find(:all).inject(0) do |i,p| # p.update_attribute(:position, i) # i+1 # end # CourseProduct.find(:all).inject(0) do |i,p| # p.update_attribute(:position, i) # i+1 # end # end # # def self.down # remove_column :products, :position # end
Comments