how to detect whether my rails is running in migration or not in environment.rb
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