如何在environment.rb中检测我的rails是否在迁移中运行
任何简单的方法来检测它? 我想在进行迁移rake时跳过envirmonment.rb中的一些代码。
我在维护的遗留应用程序中遇到此问题。 有些观察者在某一点上干扰了迁移,所以我在迁移过程中通过检查应用程序名称和参数来禁用它们
# 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
我想如果你想跳过,只需对代码发表评论(#)。
或许多选择迁移耙。
例如:rake db:migrate:up VERSION = 2000123232它的意思是,只有2000123232_create_article才能进行迁移。
或者rake db:migrate VERSION = 2000123232意味着从2000123232之后开始
或者rake db:migrate:down VERSION = 2000123232
只是耙帮助你可以看到你需要耙。
你的意思是?