Browse files

Merge commit 'jsmecham/master'

  • Loading branch information...
2 parents 8de9fda + 0b58f45 commit fec38cfbe77dbe569672c568328fe7b8db3f0b87 @technoweenie technoweenie committed Jul 1, 2008
Showing with 21 additions and 7 deletions.
  1. +20 −6 README
  2. +1 −1 lib/active_reload/connection_proxy.rb
View
26 README
@@ -1,13 +1,14 @@
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.
+The ActiveReload::MasterDatabase model uses a 'master_database' setting that
+can either be defined for all of your environments, or for each environment as
+a nested declaration:
# config/database.yml
login: &login
@@ -16,11 +17,24 @@ database.yml to serve as the master database.
port: 5432
production:
- database: slave_database_name
+ database: production_slave_database_name
<<: *login
-
+
master_database:
- database: master_database_name
+ database: production_master_database_name
+ <<: *login
+
+ staging:
+ database: staging_database_name
+ host: slave-db-pool.local
+ <<: *login
+ master_database:
+ database: staging_database_name
+ host: master-db-server.local
+ <<: *login
+
+ development: # Does not use masochism
+ database: development_database_name
<<: *login
To setup:
View
2 lib/active_reload/connection_proxy.rb
@@ -1,7 +1,7 @@
module ActiveReload
class MasterDatabase < ActiveRecord::Base
self.abstract_class = true
- establish_connection :master_database
+ establish_connection configurations[Rails.env]['master_database'] || :master_database
end
class ConnectionProxy

0 comments on commit fec38cf

Please sign in to comment.