Thursday, December 14, 2006

Rails: Running migrations in another environment

From the command line it's possible to run migrations in any environment. For example, using the code below it is possible to run migrations in the test environment.
rake db:migrate RAILS_ENV=test
Because the above code works it would appear that you could create the following rake task to automate running the migrations in the test environment.
task :test_migrate do
ENV["RAILS_ENV"] = "test"
Rake::Task["db:migrate"].invoke
end
Unfortunately, that didn't work, but the following change does work.
task :test_migrate do
ActiveRecord::Base.establish_connection "test"
Rake::Task["db:migrate"].invoke
end
Post a Comment