# How to use Postgres schemas in Rails app to separate data

**URL:** <https://www.ruby-forum.com/t/how-to-use-postgres-schemas-in-rails-app-to-separate-data/106218>\
**Category:** Rails\
**Created:** [June 7, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/how-to-use-postgres-schemas-in-rails-app-to-separate-data/106218 "2007-06-07T17:11:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathandelane](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@nathandelane](https://www.ruby-forum.com/u/nathandelane)\
**Post date:** [June 7, 2007, 5:11pm UTC](https://www.ruby-forum.com/t/how-to-use-postgres-schemas-in-rails-app-to-separate-data/106218/1 "2007-06-07T17:11:46Z")

</div>

Rails/Postgres Gurus,

Question:  
Is it possible to use Postgres schemas within a Rails app to separate  
tables  
and data between two different apps?

Problem Set:  
I am thinking of combining two apps. I want to share some data (certain  
tables) between them, but I want the migrations and other activities to  
be  
separated. I don’t want any table changes in one app to impact the  
other.

Example:  
App 1 contains order entry. App 2 contains contact management. In App  
2, I  
want to access the order history for a customer/contact. So, I create  
an  
order model in App 2 and set the table name to include the schema…e.g.  
set\_table\_name “schema1.orders”.

However, I want both apps to have their own migrations. How do I tell  
Rails  
to use a particular schema when doing migrations, fixture loads, etc.?

Alternative(s):  
The other reasonable option seems to be multiple database connections in  
each app, which I haven’t investigated much yet. I have read a little  
about  
the “magic” multi-connection stuff. I am just thinking the schema thing  
in  
Postgres might be a cleaner (read…easier for me) solution.

Any tips, alternatives, or berating on why not to pursue this would be  
appreciated.

Thanks,  
Nathan
