the complete data model. • You need features from a second database. • Your trying to migrate away from one database. • You want to run intensive queries on a reporting mirror.
class ApplicationController < ActionController::Base around_filter :cache_other_db_connections private def cache_other_db_connections SecondBase::Base.connection.cache { yield } end end
in config/initializers/*.rb DB_ONE = Sequel.connect('postgres://user:password@localhost/ db_one') DB_TWO = Sequel.connect('postgres://user:password@localhost/ db_two') # raw db query DB_TWO[:posts].where(:category => 'Ruby Loco') # in your models class Post < Sequel::Model end Post.db = DB_TWO