Log SQL queries during rake tasks
Depending on your environment, Rake will log sql queries just like any Rails process will & in the same logfile. So on your dev box, check your log/development.log file - it will contain your Rake task's queries. If you want queries logged in production, set the log level in your Rake task to DEBUG, and make sure the rake task depends on :environment.
desc "Task with SQL logging"
task :test_log => :environment do
Rails.logger.level = Logger::DEBUG
Your code here...
end
echo '' > log/development.log
rake db:migrate:redo VERSION=20141017153933
cat log/development.log
Proper answer is to put this at the beginning of rake task:
ActiveRecord::Base.logger = Logger.new STDOUT
rake db:migrate --trace
The --trace will show details