I wrote a migration script to update all previous records in ActiveRecord.
class UpdateListCompletedAtFields < ActiveRecord::Migration
def up
Car.find_each do |car|
if car.list_car_step_3_finished?
car.list_completed_at = Time.now
puts "Car #{car.id} list_completed, updating list_completed_at: #{car.list_completed_at}"
end
end
end
end
when I run the migration script, the puts message output the field car.list_completed_at correctly, but when I then get into rails console (after I extied) and try to check the data, the migration did not persist. I am wondering if I am missing anything?
Car.all.map{|m| [m.list_car_step_3_finished, m.list_completed_at]}
=>[[true, nil], [true, nil], [nil, nil], [nil, nil], [nil, nil], [nil, nil], [nil, nil], [nil, nil], [nil, nil], [true, nil], [nil, nil]]