# Where should I start? If I want to use dataschemas with post

**URL:** <https://www.ruby-forum.com/t/where-should-i-start-if-i-want-to-use-dataschemas-with-post/53464>\
**Category:** Rails\
**Created:** [February 6, 2006, 8:06pm UTC](https://www.ruby-forum.com/t/where-should-i-start-if-i-want-to-use-dataschemas-with-post/53464 "2006-02-06T20:06:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [February 6, 2006, 8:06pm UTC](https://www.ruby-forum.com/t/where-should-i-start-if-i-want-to-use-dataschemas-with-post/53464/1 "2006-02-06T20:06:41Z")

</div>

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

> **[Yahoo Mail - Organized Email](https://mail.yahoo.com)**
>
> It's time to get stuff done with Yahoo Mail. Just add your Gmail, Outlook, AOL or Yahoo Mail to get going. We automatically organize all the things life throws at you, like receipts and attachments, so you can find what you need fast. Plus, we've got...

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [February 6, 2006, 9:27pm UTC](https://www.ruby-forum.com/t/where-should-i-start-if-i-want-to-use-dataschemas-with-post/53464/2 "2006-02-06T21:27:20Z")

</div>

Saiho Y. \<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

> **[5.9. Schemas](https://www.postgresql.org/docs/7.4/ddl-schemas.html)**
>
> 5.9. Schemas 5.9.1. Creating a Schema 5.9.2. The Public Schema 5.9.3. The Schema Search Path 5.9.4. Schemas and Privileges 5.9.5. The …

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [February 6, 2006, 10:53pm UTC](https://www.ruby-forum.com/t/where-should-i-start-if-i-want-to-use-dataschemas-with-post/53464/3 "2006-02-06T22:53:40Z")

</div>

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 S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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  
> schema.
> 
> Check out

> **[5.9. Schemas](https://www.postgresql.org/docs/7.4/ddl-schemas.html)**
>
> 5.9. Schemas 5.9.1. Creating a Schema 5.9.2. The Public Schema 5.9.3. The Schema Search Path 5.9.4. Schemas and Privileges 5.9.5. The …

> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

* * *

Do You Yahoo!?  
Tired of spam? Yahoo! Mail has the best spam protection around

> **[\[object](https://mail.yahoo.com/)**
>
> \[object

---

<div class="post-metadata">

**Author:** ![sayoyo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@sayoyo](https://www.ruby-forum.com/u/sayoyo)\
**Post date:** [February 6, 2006, 11:30pm UTC](https://www.ruby-forum.com/t/where-should-i-start-if-i-want-to-use-dataschemas-with-post/53464/4 "2006-02-06T23:30:16Z")

</div>

Saiho Y. \<sayoyo@…\> writes:

> 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
