title: Rake tasks for multiple databases with different schemas
body: <p>I am working on a multi-database Rails 3 application. Each database has a different schema (and in production are located in different locations). I've set the app to talk to different databases like so:</p>
  
  <p>database.yml</p>
  
  <pre><code>development:
    adapter: mysql2
    encoding: utf8
    reconnect: false
    database: main_development
    pool: 5
    username: someuser
    password: somepassword
    socket: /tmp/mysql.sock
  
  other_development:
    adapter: mysql2
    encoding: utf8
    reconnect: false
    database: other_development
    pool: 5
    username: someuser
    password: somepassword
    socket: /tmp/mysql.sock
  </code></pre>
  
  <p>models/other_base.rb</p>
  
  <pre><code>class OtherBase &lt; ActiveRecord::Base
    self.abstract_class = true
    establish_connection "other_#{Rails.env}"
  end
  </code></pre>
  
  <p>models/some_model.rb</p>
  
  <pre><code>class SomeModel &lt; OtherBase
    # Regular stuff here
  end
  </code></pre>
  
  <p>Now, this works fine for web app, but not so well for running rake tasks, including tests (fixtures aren't loaded correctly). Is there a gem available for this? Any help appreciated.</p>
  
  <p>Also, it would be nice to create a schema.rb file that could handle the different schemas for different DBs - that is, would allow me to do things like rake db:create or db:setup and have it create multiple databases with the database-specific schema.</p>