-
Notifications
You must be signed in to change notification settings - Fork 22
/
README
43 lines (35 loc) · 2.24 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
master_slave_adapter - maurício DOT linhares AT gmail DOT com
====
This simple plugin acts as a common ActiveRecord adapter and allows you to
setup a master-slave environment using any database you like (and is supported
by ActiveRecord).
This plugin works by handling two connections, one to a master database,
that will receive all non-"SELECT" statements, and another to a slave database
that that is going to receive all SELECT statements. It also tries to do as
little black magic as possible, it works just like any other ActiveRecord database
adapter and performs no monkeypatching at all, so it's easy and simple to use
and understand.
The master database connection will also receive SELECT calls if a transaction
is active at the moment or if a command is executed inside a "with_master" block:
ActiveRecord::Base.with_master do # :with_master instructs the adapter
@users = User.all # to use the master connection inside the block
end
To use this adapter you just have to install the plugin:
ruby script/plugin install git://github.com/mauricio/master_slave_adapter.git
And then configure it at your database.yml file:
development:
database: sample_development
username: root
adapter: master_slave # the adapter must be set to "master_slave"
host: 10.21.34.80
master_slave_adapter: mysql # here's where you'll place the real database adapter name
disable_connection_test: true # this will disable the connection test before use,
# can possibly improve the performance but you could also
# hit stale connections, default is false
eager_load_connections: true # connections are lazy loaded by default, you can load gem eagerly setting this to true
master: # and here's where you'll add the master database configuration
database: talkies_development # you shouldn't specify an "adapter" here, the
username: root # value at "master_slave_adapter" is going to be used
host: 10.21.34.82
adapter: postgresql # you can use another adapter for the master connection if needed
# if you don't set it the "master_slave_adapter" property will be used