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

后端 未结 5 1283
失恋的感觉
失恋的感觉 2020-12-04 19:00

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

5条回答
  •  时光说笑
    2020-12-04 20:06

    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.

提交回复
热议问题