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

Solution 1:

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

Solution 2:

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.