0.0
No commit activity in last 3 years
No release in over 3 years
Multibase provides support for Rails to manage several databases by extending ActiveRecord tasks that create, migrate, and test your databases
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0

Runtime

>= 4.0
 Project Readme

Multibase Build Status Coverage Status Code Climate

Multiple database support for Rails.

This solution inspired by the SecondBase

Installation

Add this line to your application's Gemfile:

gem 'multibase-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install multibase-rails

Usage

database.yml

Change config/database.yml so that settings for every database are placed under the following root key:

# config/database.yml
---
default: # default key for the default database
  test:
    adapter: sqlite3
    url:     ./base/test.sqlite3
  development:
    adapter: sqlite3
    url:     ./base/development.sqlite3
  production:
    adapter: postgresql
    url:     <%= ENV['DEFAULT_BASE_URL'] %>
custom_db: # the unique name for another database
  test:
    adapter: sqlite3
    url:     ./custom_db/test.sqlite3
  development:
    adapter: sqlite3
    url:     ./custom_db/development.sqlite3
  production:
    adapter: postgresql
    url:     <%= ENV['PERSONAL_BASE_URL'] %>

Configurations

You can define your own default database key in config/application.rb

config.multibase.default_key # Default: 'default'

Rake tasks

All db: rake tasks defined for each database as db:your_database_name:command, e.g. rake db:cusom_db:create

Rails Generators

Migrations

Use multibase:migration to generate migration for specific database

rails g multibase:migration <migration_name> <database_name> <options>

Example

rails g multibase:migration CreateMyTable custom_db foo:integer baz:string 

Rails models

All models should be inherit from Multibase::Base. Use using method to specify database connection Example

class Comment < Multibase::Base
  using :my_not_default_connection
end

License

The gem is available as open source under the terms of the MIT License.