I’m trying to implement a Postgres based Rails system with multiple
schemas (one per user for security).
For that I need to set a different login user for each of the
connecting users (based on a central authentication system that sets
the login to the session info). SO I need to login as a different user
for each connection coming in.
When running a Rails app through FCGI/SCGI, is the database.yml
file loaded only when one of the runners launches, or on every
Can I change database.yml so that when it’s read with erb it’ll
replace the user with something from the session automatically?
In other words, lets say my database.yml looks like:
username: <%= session[:db_user] %>
password: <%= session[:db_pass] %>
- Will this even work?
- Will it change with each connection?
- If not, where should I call establish_connection() when a session
starts, so that I can assign the user I want to?
Once I have this figured out I’ll write a short wiki page on how to
use postgres schemas to insulate one user from the other, while not
messing with all the rails way of doing things.