I have a table in a Rails app with hundreds of thousands of records, and they only have a created_at
timestamp. I'm adding the ability to edit these records, so I want to add an updated_at
timestamp to the table. In my migration to add the column, I want to update all rows to have the new updated_at
match the old created_at
, since that's the default for newly created rows in Rails. I could do a find(:all)
and iterate through the records, but that would take hours because of the size of the table. What I really want to do is:
UPDATE table_name SET updated_at = created_at;
Is there a nicer way to do that in a Rails migration using ActiveRecord rather than executing raw SQL?