# Capistrano/SVN: Deploying different database.yml for live?

**URL:** <https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914>\
**Category:** Rails\
**Created:** [March 30, 2006, 4:15am UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914 "2006-03-30T04:15:40Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 30, 2006, 4:15am UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914/1 "2006-03-30T04:15:40Z")

</div>

Greetings,

Today I’ve been working out how to begin using Capistrano and so far I’m  
impressed. Even in my situation, learning Rails and deploying to a  
single server, it’s incredibly helpful. I do have one small question  
though:

In using Subversion I’ve used the “ignore” feature to ignore my local  
database.yml file, because my local database and my live one have  
different names.

What should I do to accommodate this in Capistrano? When I use  
Capistrano to deploy, the correct database.yml isn’t put into place  
where it should be. I’m not sure where to begin to fix this situation.

Thanks,  
Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 30, 2006, 4:26am UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914/2 "2006-03-30T04:26:44Z")

</div>

Jeff C.man wrote:

> What should I do to accommodate this in Capistrano? When I use  
> Capistrano to deploy, the correct database.yml isn’t put into place  
> where it should be. I’m not sure where to begin to fix this situation.

Well you could have two database.yml files named like database.yml.dev  
and database.yml.prod and then add a task to link or rename the correct  
one on deploy.

But, why don’t you just put all of your database configurations info  
into database.yml and select the one that you want to use based on  
whether you are in development, testing or production. This is the  
standard way to do this in Rails. Just have a look at the database.yml  
produced by “rails .”

I realize there may be reasons not to have the production database  
password in svn, but this doesn’t seem to be the problem you are having.

–

Ray

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 30, 2006, 4:32am UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914/3 "2006-03-30T04:32:48Z")

</div>

Hello Jeff !

2006/3/29, Jeff C.man [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> What should I do to accommodate this in Capistrano? When I use  
> Capistrano to deploy, the correct database.yml isn’t put into place  
> where it should be. I’m not sure where to begin to fix this situation.

Read up on “Extending Tasks”:  
[http://manuals.rubyonrails.com/read/chapter/102#page277](http://manuals.rubyonrails.com/read/chapter/102#page277)

Basically, you should create an “after\_update\_code” task which will  
link, copy or whatever you need to put the right database.yml file in  
it’s proper place.

Hope that helps !

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 30, 2006, 4:43am UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914/4 "2006-03-30T04:43:52Z")

</div>

Ray B. wrote:

> But, why don’t you just put all of your database configurations info  
> into database.yml and select the one that you want to use based on  
> whether you are in development, testing or production. This is the  
> standard way to do this in Rails. Just have a look at the database.yml  
> produced by “rails .”

Yeah, but that would make sense 🙂

That’s actually what I should do, but at the moment my production server  
seems to think it’s running in “development” and I’m not sure how to set  
it. I just posted the question on the server’s support forums, but til  
now I’ve just been ignoring it and making do.

Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 30, 2006, 5:00am UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914/5 "2006-03-30T05:00:10Z")

</div>

Jeff C.man wrote:

> That’s actually what I should do, but at the moment my production server  
> seems to think it’s running in “development” and I’m not sure how to set  
> it. I just posted the question on the server’s support forums, but til  
> now I’ve just been ignoring it and making do.

If all else fails, have a look at the top of config/environment.rb.  
There is a method there that will set you server into production mode by  
default.

Then you just have to set RAILS\_ENV to development on your local box.

–

Ray

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 30, 2006, 5:00am UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914/6 "2006-03-30T05:00:10Z")

</div>

I’ve found that setting RAILS\_ENV in /etc/bash\_profile (or equivalent)  
generally will do the trick.

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 30, 2006, 5:25am UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914/7 "2006-03-30T05:25:41Z")

</div>

Tom M. wrote:

> I’ve found that setting RAILS\_ENV in /etc/bash\_profile (or equivalent)  
> generally will do the trick.
> 
> –  
> – Tom M.

I’m a Linux noob, what would be the exact syntax?

set RAILS\_ENV=production

? Or should it be

set RAILS\_ENV=“production”

Or something different?

Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 30, 2006, 6:27am UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914/8 "2006-03-30T06:27:50Z")

</div>

export RAILS\_ENV=production

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 30, 2006, 7:04am UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914/9 "2006-03-30T07:04:18Z")

</div>

Just to add on this - you need the rails runner user to have this  
setting in it’s ~/.bash\_profile. If it’s cgi, then it’s the web server  
user, if it’s FastCGI launched through spawner, it’s the user calling  
spawner.

Guy.

On 3/29/06, Tom M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > But, why don’t you just put all of your database configurations info  
> > > seems to think it’s running in “development” and I’m not sure how  
> > > Rails mailing list  
> > > removed\_email\_address@domain.invalid  
> > > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Family management on rails: [http://www.famundo.com](http://www.famundo.com) - coming soon!  
My development related blog: [http://devblog.famundo.com](http://devblog.famundo.com)

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 30, 2006, 7:33am UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914/10 "2006-03-30T07:33:21Z")

</div>

I got a reply from RailsPlayground, my web host, and they advised me to  
set the environment to “production” by uncommenting the relevant line in  
my application’s “environment.rb”, which… doesn’t exactly help me.

If I set production in the environment.rb, I’m still in the situation  
where Capistrano and SVN would be deploying my local environment.rb to  
the live server, which would just end up with me running production at  
home and on live, rather than development in both places, like I am now.

Not sure what to do about it.

Jeff

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 30, 2006, 8:19am UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914/11 "2006-03-30T08:19:57Z")

</div>

Jeff C.man wrote:

> I got a reply from RailsPlayground, my web host, and they advised me to  
> set the environment to “production” by uncommenting the relevant line in  
> my application’s “environment.rb”, which… doesn’t exactly help me.
> 
> If I set production in the environment.rb, I’m still in the situation  
> where Capistrano and SVN would be deploying my local environment.rb to  
> the live server, which would just end up with me running production at  
> home and on live, rather than development in both places, like I am now.
> 
> Not sure what to do about it.

Try this from my earlier response:

> Then you just have to set RAILS\_ENV to development on your local box.

You have more control over your local environment than you have over  
your server environment if you are in a hosted environment.

–

Ray

---

<div class="post-metadata">

**Author:** ![jeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e19b73/32.png) [@jeff](https://www.ruby-forum.com/u/jeff)\
**Post date:** [March 30, 2006, 12:08pm UTC](https://www.ruby-forum.com/t/capistrano-svn-deploying-different-database-yml-for-live/102914/12 "2006-03-30T12:08:29Z")

</div>

Alternately, create a ‘shared’ directory at the same level as ‘current’.  
In ‘shared/config’ place the ‘database.yml’ file of interest, then  
symlink (ln -s) to it in an after\_update in your deploy.rb.

I do similar things to wire up ‘vendor’ and the like.

-San
