Migrating data in a Rails migration

Turns out it’s easy to whack any old piece of code into the migration for migrating your data, for example these work well for some arbitrary SQL statements (I used UPDATE ones…)

ActiveRecord::Base.connection.select_one('SELECT COUNT(*) FROM mytable')
ActiveRecord::Base.connection.execute('SELECT * FROM mytable')

Thanks revgeorge.

Leave a Reply

Your email address will not be published. Required fields are marked *