Dr Nic

“Reads -> slaves, writes -> master” plugin

Another solution to multiple connections in Rails has been put together by the Revolution Health team.

Look at this sweet database.yml syntax:

dbs:

  database: master_db
  host: master-host

  read_only:
    database: slave_db
    host: slave-host

ActsAsReadonlyable adds support of multiple read-only slave databases to ActiveRecord models. When a model is marked with acts_as_readonlyable, some of AR finders are overridden to run against a slave DB. The supported finders are find, find_by_sql, count_by_sql, find_[all_]by_*, and reload.

README all about it.

Related posts:

  1. Dr Nic’s Magic Show at RejectConf2007 Update: there is a patch available for edge rails to...
  2. Magic Multi-Connections: A “facility in Rails to talk to more than one database at a time” At this point in time there’s no facility in Rails...
  3. [ANN] Dr Nic’s Magic Models 0.8 – Validate Anything, Anytime, Anywhere Ladies and Gentlemen, welcome one and all to the greatest...
  4. [BTS] Magic Models vs ActiveRecords – Efficiency Dr Nic’s Magic Models are magical, that goes without saying....
  5. [BTS] Magic Models – Class creation [BTS] = Behind the Scenes; also a news-like TV show...

3 Responses to ““Reads -> slaves, writes -> master” plugin”

  1. AkitaOnRails says:

    Absolutely sweet, two solutions for a problem that started with a discussion not a week old. I was guessing that perhaps a big website as Revolution Health didn’t came by a similar problem than Twitter’s. You Magic Multi Connections and this ActsAsReadonlyable both goes by the same direction and they are fine. Yours expects an explicit conn proxy method – which I like. And Revolution’s approach is more transparent although we should be aware of any conflicts maybe with our own overwriting the finders and check out the logs to see if every finder is actually hitting the slaves. Anyhoo, congratulations for both authors for your creativity and quick response to the community.

  2. [...] “Reads -> slaves, writes -> master” plugin Looks like the Ruby community is stepping up to tackle the scale problem. I hope they keep this development up and don’t just say “we fixed it”. [via Dirk] [...]

  3. [...] Dr Nic » “Reads -> slaves, writes -> master” plugin (tags: rubyonrails database scaling) [...]