README.md in secondbase-1.0.1 vs README.md in secondbase-2.0.0

- old
+ new

@@ -5,11 +5,11 @@ * [Using SecondBase To Provide Some Level Of Sanity](http://technology.customink.com/blog/2016/01/10/two-headed-cat-using-secondbase-to-provide-some-level-of-sanity-in-a-two-database-rails-application/) * [Rails Multi-Database Best Practices Roundup](http://technology.customink.com/blog/2015/06/22/rails-multi-database-best-practices-roundup/) [![Gem Version](https://badge.fury.io/rb/secondbase.png)](http://badge.fury.io/rb/secondbase) -[![Build Status](https://secure.travis-ci.org/customink/secondbase.png)](http://travis-ci.org/customink/secondbase) +[![Build Status](https://travis-ci.org/customink/secondbase.svg?branch=master)](https://travis-ci.org/customink/secondbase) ## Usage To get started with your new second database, update your database.yml to include a `secondbase` config key. All SecondBase configurations per Rails environment go under this config key. @@ -120,9 +120,53 @@ config.second_base.config_key # Default: 'secondbase' ``` * `path` - Used as location for migrations & schema. Path is relative to application root. * `config_key` - The key to in database.yml/configurations to search for SecondBase configs. + + +## Advanced Usage + +#### Twelve-Factor & DATABASE_URL + +We love the [Twelve Factors](http://12factor.net) principals and using tools like Dotenv with Rails. Using SecondBase does not mean you have to abandon these best practices. You will however need to take advantage of a [new feature](https://github.com/rails/rails/pull/14633) in Rails 4.1 and upward that allows database.yml configurations to leverage a `:url` key that will resolve and merge the same connection string format consumed by `DATABASE_URL`. For example: + +```yaml +development: + database: encom-pg_development + url: <%= ENV.fetch('DATABASE_URL') %> +test: + database: encom-pg_test + url: <%= ENV.fetch('DATABASE_URL') %> +production: + url: <%= ENV.fetch('DATABASE_URL') %> + +secondbase: + development: + database: encom-mysql_development + url: <%= ENV.fetch('DATABASE_URL_SECONDBASE') %> + test: + database: encom-mysql_test + url: <%= ENV.fetch('DATABASE_URL_SECONDBASE') %> + production: + url: <%= ENV.fetch('DATABASE_URL_SECONDBASE') %> +``` + +There are many ways to use Dotenv and enviornment variables. This is only one example and we hope it helps you decide on which is best for you. + +#### The ActiveRecord Query Cache + +Rails only knows about your base connection for the Rack-based query cache. In order to take advantage of this feature for your SecondBase, you will need to set an arround filter in your controller. + +```ruby +class ApplicationController < ActionController::Base + around_filter :query_cache_secondBase + private + def query_cache_secondBase + SecondBase::Base.connection.cache { yield } + end +end +``` ## Versions The current master branch is for Rails v4.0.0 and up and. We have older work in previous v1.0 releases which partial work for Rails 3.2 or lower. These old versions are feature incomplete and are not supported.