如何检测我的rails是否正在迁移中运行在environment.rb中 [英] how to detect whether my rails is running in migration or not in environment.rb

查看:81
本文介绍了如何检测我的rails是否正在迁移中运行在environment.rb中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么简单的方法可以检测到它吗?在进行迁移rake时,我想跳过envirmonment.rb中的一些代码.

any easy way to detect it? I want to skip some codes in envirmonment.rb when doing migration rake.

推荐答案

我在维护的旧版应用程序中遇到了这个问题.有一些观察者会干扰迁移到某个特定点,因此我在迁移期间通过检查应用程序名称和参数来禁用它们

I had this problem in a legacy application I was maintaining. There were some observers that were interfering with migrations past a certain point, so I disabled them during migration by checking the application name and arguments

  # Activate observers that should always be running
  # config.active_record.observers = :cacher, :garbage_collector, :forum_observer# observers break a migrate from VERSION xxx - disable them for rake db:migrate
unless ( File.basename($0) == "rake" && ARGV.include?("db:migrate") )
  config.active_record.observers = :user_observer
end

这篇关于如何检测我的rails是否正在迁移中运行在environment.rb中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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