Wrap Migration in Transaction

For data-only modifications, you can use a simple transaction do statement like anywhere else:

class TransactionTest < ActiveRecord::Migration def self.up transaction do execute “insert into some_table(some_column) values(‘some_value’)”

end

end

def self.down end end

For a cool slideshow that deals with this a little check out page 18 of: http://www.chariotsolutions.com/slides/PhillyOnRails-Migrations.pdf

If you want to make the switch to a database that supports transactions for ddl (like postgres), you can also install this plugin and it should solve most of your problems:

http://www.redhillconsulting.com.au/rails_plugins.html#transactional_migrations

I haven’t tried that latest plugin, but I regularly use transaction do for my more complicated data manipulations scripts.

Jeff