Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

ActiveRecord connection proxy for master/slave connections

branch: master

This branch is 0 commits ahead and 0 commits behind master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README
README
masochism
==============

The masochism plugin provides an easy solution for Ruby on Rails applications to
work in a replicated database environment. Connection proxy sends some database
queries (those in a transaction, update statements, and ActiveRecord::Base#reload) 
to a master database, and the rest to the slave database. 

The ActiveReload::MasterDatabase model uses a 'master_database' setting in 
database.yml to serve as the master database.

  # config/database.yml
  login: &login
    adapter: postgresql
    host: localhost
    port: 5432

  production:
    database: slave_database_name
    <<: *login
    
  master_database:
    database: master_database_name
    <<: *login

To setup:

Whether you want this in production only, or maybe just your deployment server, 
is up to you. Just call the following method in your desired environment file.

  ActiveReload::ConnectionProxy.setup!

Some suggestions:

  * in a config/initializer
  * config.after_initialize block

If you want a model to always use the Master database, you can inherit 
ActiveRelaod::MasterDatabase.  Any models with their own database connection
will not be affected.

Setting up your own proxies:

  # Sets up MyMaster's connection as the master database connection for User.
  ActiveReload::ConnectionProxy.setup_for MyMaster, User
  
Something went wrong with that request. Please try again.