README.md in slavery-2.0.0 vs README.md in slavery-2.1.0

- old
+ new

@@ -1,7 +1,9 @@ # Slavery - Simple, conservative slave reads for ActiveRecord +[![Build Status](https://travis-ci.org/kenn/slavery.svg)](https://travis-ci.org/kenn/slavery) + Slavery is a simple, easy to use gem for ActiveRecord that enables conservative slave reads, which means it doesn't automatically redirect all SELECTs to slaves. Instead, you can do `Slavery.on_slave { User.count }` to send a particular query to a slave. Background: Probably your app started off with one single database. As it grows, you would upgrade to a master-slave replication for redundancy. At this point, all queries still go to the master and slaves are just backups. With that configuration, it's tempting to run some long-running queries on the slave. And that's exactly what Slavery does. @@ -47,10 +49,17 @@ development_slave: <<: *common ``` +Optionally, you can use a database url for your connections: + +```yaml +development: postgres://root:@localhost:5432/myapp_development +development_slave: postgres://root:@localhost:5432/myapp_development_slave +``` + At this point, Slavery does nothing. Run tests and confirm that nothing is broken. ## Usage To start using Slavery, you need to add `Slavery.on_slave` in your code. Queries in the `Slavery.on_slave` block run on the slave. @@ -99,10 +108,16 @@ ```ruby Slavery.on_slave { User.create } # => ActiveRecord::StatementInvalid: Mysql2::Error: INSERT command denied... ``` +With Postgres you can set the entire database to be readonly: + +```SQL +ALTER DATABASE myapp_development_slave SET default_transaction_read_only = true; +``` + It is a good idea to confirm this behavior in your test code as well. ## Disable temporarily You can quickly disable slave reads by dropping the following line in `config/initializers/slavery.rb`. @@ -137,6 +152,7 @@ Slavery.spec_key = "slave" #instead of production_slave ``` ## Changelog +* v2.1.0: Debug log support / Database URL support / Rails 3.2 & 4.0 compatibility (Thanks to [@citrus](https://github.com/citrus)) * v2.0.0: Rails 5 support