How should I use Activerecord to map to a database
schemas with Psotgresql? Where can I find the
infomation about how to use schemas in Rails?
Can you give some more details on what you are trying to do?
Are you trying to have one RoR app’s set of model objects map to
schemas at the same time :
Blog object maps to schema X
Post object maps to schema Y
have different instances(dev, test, qa, integration) of an app map to
schemas in the same database?
integration app instance maps to schema INT
qa app instance maps to schema QA
One thing I’ve done is have a shared integration database, where each
log in with their own db username so they can test in a more complete
environment rather than their own local sandbox which might have alot of
mocked out. Then using postgres’ schema search path feature, each
login’s schema is the first in the search path, so when they launch
their app it
connects to their own schema instead of the public schema.
what I’m trying to do is quit simple, we have already
a database with several different schemas, we try to
build a RoR application on the database, I have
examples about how to map a Activerecords class to a
table, but it doesn’t explain how to map a
Activerecords class to a schemas-table. and how should
I configurate database.yml file…
trying to do?
of an app map to different
which might have alot of things
mocked out. Then using postgres’ schema search path
feature, each user’s db
login’s schema is the first in the search path, so
when they launch their app it
connects to their own schema instead of the public
Let’s see if I understand you correctly. Say we have a basic model with
In your database:
you have a schema named blog_app
you have two tables, blog_app.blogs and blog_app.posts
You can do a number of things, none really requiring any ‘special’
you can create a user named blog_app, then since the user name matches
schema name, the default postgres schema search will find the tables in
blog_app schema before anything in the public schema
instead say you have a db login named saiho, then login as saiho via
set the search path to explicitly:
SET search_path TO $user,blog_app,public;
I hope that helps
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.