I guess you should check that the Make. Count is equal to the total unique makes in lineitems before removing the column, and raise an error if it does not. As migrations are transactional, if it blows up, the schema isn't changed and the migration isn't marked as executed.
Therefore, you could do something like this.
I guess you should check that the Make. Count is equal to the total unique makes in lineitems before removing the column, and raise an error if it does not. As migrations are transactional, if it blows up, the schema isn't changed and the migration isn't marked as executed.
Therefore, you could do something like this: class CreateMakesAndMigrateFromLineItems Timestamps end makes = LineItem.all. Collect(:&make). Uniq makes.
Each { |make| Make. Find_or_create_by_name make } Make. Count == makes.
Length? Remove_column(:line_items, :make) : raise "Boom! " end def self.
Down # You'll want to put logic here to take you back to how things were before. Just in case! Drop_table :makes add_column :line_items, :make end end.
You can put regular ruby code in your migration, so you can create the new table, run some code across the old model moving the data into the new model, and then delete the columns from the original model. This is even reversible so your migration will still work in both directions. So for your situation, create the Make table and add a make_id to the lineitem.
Then for each line item, find_or_create with the make column on lineitem, setting the returned id to the new make_id on lineitem. When you are done remove the old make column from the lineitem table.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.