So today, I discovered a "good idea" for migrations.
Put your database schema changes in one migration, then your data changes in the next. This becomes self-evident when you mix the two and watch as part way through your migration, the data change fails and suddenly your tables have been altered.
Subscribe to:
Post Comments (Atom)
2 comments:
You can also use the ModelName.reset_column_information information method. ie:
def self.up
add_column :product, :cost, :integer
Product.reset_column_information
Product.find(:all).each { |p| # do stuff to p }
end
However, in my case, Product.find(:all).each {|p| p.do_it!} threw an exception.
Then, to run the migration again (because it didn't complete), it tried to add the column again.
Post a Comment