Also known as the <<"User has many Databases" question.>>
The environment
My app is modeled like so:
user has_many databases
database has_many tables
table has_many rows
row habtm(+value) columns
you get the idea!
So instead of modelling a database inside a database, I would like to have:
- a sqlite3 database that holds the users and
- many sqlite databases for each user
Each user will LCRUD his tables in his databases (similar to phpmyadmin)
The problem
I would like to have thread safe per-request configuration for database connection and table_name
class Table < ActiveRecord::Base
end
# in some controller
# set the connection to the user-selected database from some DB list
Table.connection = current_user.session.connection
# set the name to the user-selected table from some tables list
Table.table_name = params[:table_name]
@rows = Table.all #display them
EDIT
As you see, the connection is global and shared between threads, but as per my app's specs, each user has it's own connection. Now imagine that 2 different users make 2 requests at the same time.
The options?
- I give up ActiveRecord and use bare-bones DB driver
- I give up thread saftey