MySQL Replication Adapter for Rails
Posted by Sam
A few weeks ago Rapleaf released an adapter to handle MySQL replication inside Rails. Many Ruby on Rails users will remember a while back Dr Nic released Magic Multi-Connections that allowed Rails applications to talk to more than one database at a time.
I have to say that I much prefer the syntax of the Rapleaf adapter. In my mind it's a better way to handle MySQL slaves. Although I do have a couple of complaints. For starters, MySQL Replication Adapter is just that. A MySQL Replication Adapter. I'd like to see the same code available for all databases. Dr Nic's Magic Multi-Connections gem does it and it seems like something that should be database agnostic. My other nit pick is that you must use the syntax below to send queries to your slaves.
MyModel.find(:all, :use_slave => true)
I like that using the slaves for all reads isn't an all or nothing affair, but it seems to me that
Tags: rubyonrails
Comments
11 days later Bryan Duxbury said
Thanks for taking a look at MysqlReplicationAdapter. Your ideas for new features are good. In a later version, it's conceivable that it will be expanded to an entirely database-agnostic approach. It probably wouldn't take much to go down that road. Likewise, I think it would be reasonable to add a configuration parameter that lets you choose whether :use_slave defaults to true or false. The reason we chose that it default to false is because multiple databases are often added to a project as an afterthought, which can lead to a real development mess.