I have a rails project running that defines the standard production:, :development and :test DB-connections in config/database.yml
In addition I have a quiz_development: and quiz_production: definition pointing to a differnet host/db/user/password
My goal now is to define a Migration that uses "quiz_#{RAILS_ENV
}`" as its database configuration.
What I have tried (and failed):
Question:
How can I make rake db:migrate use that other database definition?
Thanks, Frank
There's a much easier answer. Add this to your migration:
def connection
ActiveRecord::Base.establish_connection("quiz_#{Rails.env}").connection
end
That's for Rails 3.1. For Rails 2.X or 3.0 it's a class function instead (eg def self.connection
)