Wrap Migration in Transaction

Hello Caleb,

I've also tried doing:
ActiveRecord::Base.transation do
  %x[rake migrate]
end

But this, obviously, doesn't work since %x[rake migrate]
spanws a new process outside of the scope of the
transactioning.

Any ideas?

To invoke a Rake task in a migration, you can do :

def self.up
   Rake::Task[my_task].invoke
end

I have tried with : Rake::Task['stats'].invoke and it works.
However, it can be dangerous, what will happen with a
Rake::Task['db:migrate'] ? infinite loop ? :slight_smile: it could be a mess...
I think a rake db task would work, but you have to be careful.

HTH,
     -- Jean-François.