Currently, to support rails 3.1 til 3.2.3, we need to install latest version (1.7.1)
gem 'db-charmer', '>= 1.7.1', :require => 'db_charmer'
Assume that we have two database server at 192.168.1.14 and 192.168.1.15
common: &common
adapter: postgresql
database: my_db
username: postgres
password: postgres
port: 5432
pool: 50
timeout: 5000
test:
<<: *common
database: bet_test
host: localhost
production:
<<: *common
host: 192.168.1.14 # *this trick avoids broken startup, and migration*
sql1:
<<: *common
host: 192.168.1.14 # master
sql2:
<<: *common
host: 192.168.1.15 # slave
Model
class Post < ActiveRecord::Base
# add this method to models that needs multiple database queries
db_magic :connection => :sql1, :slave => :sql2
attr_accessible :body, :title
end
By default, SELECT
queries will access slave databases.
For more detail, visit http://kovyrin.github.com/db-charmer/index.html