I am working on a multi-database Rails 3 application. Each database has a different schema (and in production are located in different locations). I've set the app to talk to different databases like so:
database.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: main_development
pool: 5
username: someuser
password: somepassword
socket: /tmp/mysql.sock
other_development:
adapter: mysql2
encoding: utf8
reconnect: false
database: other_development
pool: 5
username: someuser
password: somepassword
socket: /tmp/mysql.sock
models/other_base.rb
class OtherBase < ActiveRecord::Base
self.abstract_class = true
establish_connection "other_#{Rails.env}"
end
models/some_model.rb
class SomeModel < OtherBase
# Regular stuff here
end
Now, this works fine for web app, but not so well for running rake tasks, including tests (fixtures aren't loaded correctly). Is there a gem available for this? Any help appreciated.
Also, it would be nice to create a schema.rb file that could handle the different schemas for different DBs - that is, would allow me to do things like rake db:create or db:setup and have it create multiple databases with the database-specific schema.