acts_as style extension provides the capabilities for using multiple database configuration files. Any model can
specify what database config file to use by using a Rails 3.2 style self.config_file= method.
In your Gemfile:
Or, from the command line:
gem install multi_config
class DifferentTable < ActiveRecord::Base self.config_file = 'other_db' end # In config/other_db.yml development: &development database: db/other_db host: localhost adapter: sqlite3 test: <<: *development
All database config files should be similar to the database.yml. You need to specify configuration for all the environments in use like you would specify in database.yml.
ActiveRecord uses ActiveRecord::Base.configurations hash to store configurations. This extension modifies the configurations
hash by adding the configurations from the other database files. The keys for the configuration in the other config are namespaced.
For e.g. if you specify
other_db config file with environments
development then configurations hash would have
these configs in
If you need to create migrations for the other db, then you will have to make modifications in the migration file. See this
how to do that. The parameter for
establish_connection would be the namespaced key for you config.
All versions require Rails 3.0.x and higher. Tested for Rails 4
- Add support for generators where you can specify which db file to use in the rails generate command. Would mitigate the need to manually modify migrations.
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
- Fork the project
- Start a feature/bugfix branch
- Commit and push until you are happy with your contribution
- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
- Send me a pull request
- Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
- Run tests -
- Generate test coverage report -
rake coverage. Coverage report path - coverage/index.html
- Generate documentation -
Copyright (c) 2012 Shadab Ahmed, released under the MIT license