public
Description: ActiveRecord connection proxy for master/slave connections
Clone URL: git://github.com/technoweenie/masochism.git
technoweenie (author)
Sun May 18 16:49:44 -0700 2008
commit  cccfa41154f28953944f063c9682a4a05308e861
tree    c1dfc23e5b75ddfde507ffcce48a5e984464cb23
parent  a6933cae9b2634461006c17f7a5412237ef3e8bb
name age message
file LICENSE Fri Oct 05 22:59:57 -0700 2007 allow some more flexibility on when exactly the... [rick]
file README Mon Mar 03 21:26:28 -0800 2008 Realized I erased a line on accident. Adding it... [Robby Russell]
directory lib/ Sun May 18 16:49:44 -0700 2008 delegate #execute to master [javier ramirez] [technoweenie]
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