how to detect whether my rails is running in migration or not in environment.rb

ε祈祈猫儿з 提交于 2019-11-28 02:42:22

问题


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


回答1:


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



回答2:


i think if u want to skip, just comment (#) on code.

or many choose on migration rake.

for example : rake db:migrate:up VERSION=2000123232 its mean , only 2000123232_create_article do migration.

or rake db:migrate VERSION=2000123232 mean start from after 2000123232

or rake db:migrate:down VERSION=2000123232

just rake help u can see what u need to rake.

Do you mean that?



来源:https://stackoverflow.com/questions/1858230/how-to-detect-whether-my-rails-is-running-in-migration-or-not-in-environment-rb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!