Browse Source

Make migration robust to model changes

topic-sass
Jason Denney 11 years ago
parent
commit
af05d1a0c6
  1. 6
      db/migrate/20131019170248_alter_bike_wheel_to_id.rb

6
db/migrate/20131019170248_alter_bike_wheel_to_id.rb

@ -11,8 +11,7 @@ class AlterBikeWheelToId < ActiveRecord::Migration
else
wheel_size_id = wheel_size.id
end
bike.bike_wheel_size_id = wheel_size_id
bike.save
bike.update_attribute(:bike_wheel_size_id, wheel_size_id)
end
remove_column :bikes, :wheel_size
@ -24,8 +23,7 @@ class AlterBikeWheelToId < ActiveRecord::Migration
Bike.find_each do |bike|
wheel_size = BikeWheelSize.find_by_id(bike['bike_wheel_size_id'])
bike.wheel_size = wheel_size.rdin.to_i
bike.save
bike.update_attribute(:wheel_size, wheel_size["rdin"].to_i)
end
remove_column :bikes, :bike_wheel_size_id

Loading…
Cancel
Save