Saiho Yuen
2006-Feb-06 19:05 UTC
[Rails] where should I start? If I want to use dataschemas with postgresql?
Hi, 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? Thanks you very much Saiho __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Alex Soto
2006-Feb-06 20:24 UTC
[Rails] Re: where should I start? If I want to use dataschemas with postgresql?
Saiho Yuen <sayoyo@...> writes:> > Hi, > > 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 different db schemas at the same time : Blog object maps to schema X Post object maps to schema Y or have different instances(dev, test, qa, integration) of an app map to different 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 user can 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 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 schema. Check out http://www.postgresql.org/docs/7.4/interactive/ddl-schemas.html
Saiho Yuen
2006-Feb-06 21:51 UTC
[Rails] Re: where should I start? If I want to use dataschemas with postgresql?
Hi, 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... how can we do this? Thanks you very much Saiho --- Alex Soto <apsoto@gmail.com> wrote:> Saiho Yuen <sayoyo@...> writes: > > > > > Hi, > > > > 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 different db > schemas at the same time : > Blog object maps to schema X > Post object maps to schema Y > > or > > have different instances(dev, test, qa, integration) > of an app map to different > 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 user can > 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 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 > schema. > > Check out >http://www.postgresql.org/docs/7.4/interactive/ddl-schemas.html> > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Alex Soto
2006-Feb-06 22:29 UTC
[Rails] Re: where should I start? If I want to use dataschemas with postgresql?
Saiho Yuen <sayoyo@...> writes:> > Hi, > > 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... > > how can we do this?Let''s see if I understand you correctly. Say we have a basic model with Blogs and Posts. 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'' database.yml setup: - you can create a user named blog_app, then since the user name matches the schema name, the default postgres schema search will find the tables in the blog_app schema before anything in the public schema - instead say you have a db login named saiho, then login as saiho via psql and set the search path to explicitly: SET search_path TO $user,blog_app,public; I hope that helps Alex