Is it possible to output the SQL change scripts that 'rake db:migrate' produces?

Building on @qarol but even cooler, add this Rake task to one of your Rake files:

task :log => :environment do
  ActiveRecord::Base.logger = Logger.new(STDOUT)
end

Then you can call ANY Rake task and have the output logged:

rake log db:migrate

You can create a Rake task in lib/tasks/:

namespace :db do
  desc 'Make migration with output'
  task(:migrate_with_sql => :environment) do
    ActiveRecord::Base.logger = Logger.new(STDOUT)
    Rake::Task['db:migrate'].invoke
  end
end

Then call rake db:migrate_with_sql to log the migration.


The SQL output is captured in your environment log file e.g. development.log