# Different DB connections for migrations vs. running app

**URL:** <https://www.ruby-forum.com/t/different-db-connections-for-migrations-vs-running-app/101970>\
**Category:** Rails\
**Created:** [August 8, 2006, 11:19pm UTC](https://www.ruby-forum.com/t/different-db-connections-for-migrations-vs-running-app/101970 "2006-08-08T23:19:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [August 8, 2006, 11:19pm UTC](https://www.ruby-forum.com/t/different-db-connections-for-migrations-vs-running-app/101970/1 "2006-08-08T23:19:49Z")

</div>

All,

I’ve run into a situation where I want the owner of my DB tables to be  
different than the user that accesses them during application runtime.

I believe that I can just set up another DB connection profile (with a  
name other than “production”) in database.yml and then pass that as  
RAILS\_ENV to db:migrate instead of “production”.

Anyone see any problems with this?

Yay - deployment issues.

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [August 8, 2006, 11:54pm UTC](https://www.ruby-forum.com/t/different-db-connections-for-migrations-vs-running-app/101970/2 "2006-08-08T23:54:13Z")

</div>

This seems to work. I did the following:

Set up a new DB profile named prod\_migrate that was only different than  
the existing production profile because of username/password.

Copied the config/environments/production.rb file to  
config/environments/prod\_migrate.rb

and I was able to migrate into production using:

rake db:migrate RAILS\_ENV=prod\_migrate

I’m under the impression that the config/environments/xxx.rb file is  
necessary in case you’ve made sweeping configuration changes to the way  
that database tables and stuff are handled. Otherwise, it’s a bit of a  
pain.

Wes
