是否可以输出“rake db:migrate"生成的 SQL 更改脚本? [英] Is it possible to output the SQL change scripts that 'rake db:migrate' produces?

查看:30
本文介绍了是否可以输出“rake db:migrate"生成的 SQL 更改脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以输出 'rake db:migrate' 生成的 SQL 更改脚本?

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

推荐答案

您可以在 lib/tasks/ 中创建 Rake 任务:

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

然后调用 rake db:migrate_with_sql 来记录迁移.

Then call rake db:migrate_with_sql to log the migration.

这篇关于是否可以输出“rake db:migrate"生成的 SQL 更改脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆