MyReplication is an extention of the existing rails’ mysql database adapter that is designed to help applications switch connection to another database server in a replication database system.
rails plugin install git@github.com:minhnghivn/my_replication.git
You need to specify a master database along with replicated ones in database.yml. For example:
development: adapter: mysql database: masterdb pool: 5 username: minhnghivn password: secret host: localhost replicas: - name: replica1 database: db1 username: minhnghivn password: secret host: localhost - name: replica2 database: db2 username: minhnghivn password: secret host: localhost
Use “replication” block to allow switching connection (randomly) to one of the replicated databases (rather than the master one) then executing the statement inside the block
User.replication do list = User.all end
You can also explicitly specify the database connection with “using” block
User.using(:replica1) do list = User.all end
Copyright © 2011 Nghi Pham, released under the MIT license