I’m working on upgrading my project from rails 3.0.9 to rails 3.2.5. I’m using multiple databases and when running the migration in rails 3.2.5 everything runs ok but everything it’s created in the default database instead of it’s corresponding database.
I thing it’s a problem with the connection pool but the bug with connection pool was fixed for rails 3.1.x
These are my models:
class Account < ActiveRecord::Base
establish_connection :accounts
end
class Patient < ActiveRecord::Base
end
:accounts it’s the connection to the other database while the other classes uses the default connection:
this my database.yml (I’m using an external file so I can modify the database connection without changing the code).
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: <%= database_config_file['database_dev'] %>
pool: 5
username: <%= database_config_file['username'] %>
password: <%= database_config_file['password'] %>
socket: /var/lib/mysql/mysql.sock
accounts:
adapter: mysql2
encoding: utf8
reconnect: false
database: <%= database_config_file['database_account'] %>
pool: 5
username: <%= database_config_file['username'] %>
password: <%= database_config_file['password'] %>
socket: /var/lib/mysql/mysql.sock
this are my migrations for the classes:
class CreateAccounts < ActiveRecord::Migration
def self.connection
Account.connection #Account model has a connection to the database I want
end
...
end
Hope someone can help
Your DB where you’re planing to make migrations has to be specified under
developmentkey (unless you want to create new environment) and your old DB — under, say,old_dbin your yml-file.Then I suggest you to create
legacy_base.rbin yourmodels/folder with the following contents:Then for each model that belongs to your old DB you have to replace:
with:
This way your ‘heritage’ will use your legacy DB and newly created models/migrations will use your new DB without any tricks.
I hope I understood your intentions.