I have a situation where my app needs to connect to a database on request. The data model of the databases is identical, but I need to connect to different ones in parallel. For instance, my RESTful route might look like this
/database/:database_id/user/:user_id # Get user :user_id from database :database_id
I've looked at similar questions, and they all recommend using ActiveRecord::Base#establish_connection
. These questions, however, don't seem to handle the case of accessing multiple databases simutaeously while using the same model classes. My worry is that I will get one request, establish a connection, start reading from the database, but then have a new request come in and change the connection of ActiveRecord. Is this a legitimate worry? I'm running this code on Ruby 1.8.7 using Rails 3.0.
Thanks. - Max