Forum: Ruby on Rails multi_db

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C84986cba3a65208de336a63354e1f91?d=identicon&s=25 erik (Guest)
on 2009-05-27 06:07
(Received via mailing list)
I would like to use the multi_db gem  to connect to multiple slave
databases.  It looks pretty easy as long as your app has a single
application database.  For example:
production:
  adapter: mysql
  database:  a_production
  username: blahblah
  password:
  host:     10.0.0.1
  port:     3306


production_slave_database_1:
  adapter: mysql
  database:  a_production
  username: blahblah
  password:
  host:     10.0.0.3
  port:     3306

production_slave_database_2:
  adapter: mysql
  database:  a_production
  username: blahblah
  password:
  host:     10.0.0.4
  port:     3306

The issue I am having is I can't figure out how to configure it to
work with multiple application databases. Let's say your app has 2
databases, your main app database and data database.  The app database
has users info and user created info while the data database has a lot
of read only data that gets updated say...once a week.

You might create a
production:
  adapter: mysql
.
.
.
production_data:
  adapter: mysql
.
.
.

Then you might want slave/s for each of those databases.  You can use
establish_connection in the models that need to access the
production_data database.  There is a way to do it with masochism like
this:

##example, showing the setup of a different master/slave combo using
setup_for
config.after_initialize do
    ActiveReload::ConnectionProxy.setup!
    ActiveReload::ConnectionProxy.setup_for SpeciesSchemaWriter,
SpeciesSchemaModel
  end
But, as far as I know you can only use a single slave with masochism,
is that true?

Thanks for any help.
Erik
This topic is locked and can not be replied to.