I’m not sure the “right” way to do this, so I wanted to ask the community. Probably a simple question.
I have a file “dbutils.rb” that I want to automatically include to have available whenever I run a “rake db:migrate”, without putting it in application.rb and without putting it in every single db migration.
Where would I put my require to make this happen?
Rails defines
$rails_rake_task = truein the:environmenttask.The
:environmenttask again is always loaded when you run:migrate(it is loaded for other Rake tasks also). You could use this to addrequire "dbutils"to your environment.rb when$rails_rake_taskistrue. And skip loading otherwise.The other option is a custom Rake task like fl00r suggested.