# How does rake decide which database to modify?

**URL:** <https://www.ruby-forum.com/t/how-does-rake-decide-which-database-to-modify/73373>\
**Category:** Rails\
**Created:** [October 24, 2006, 8:26am UTC](https://www.ruby-forum.com/t/how-does-rake-decide-which-database-to-modify/73373 "2006-10-24T08:26:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [October 24, 2006, 8:26am UTC](https://www.ruby-forum.com/t/how-does-rake-decide-which-database-to-modify/73373/1 "2006-10-24T08:26:33Z")

</div>

Hi All,

I created an 001-xxx initial migration and updated it with results of a  
schema::dump, removing the :force =\> true.

Then I ran rake migrate and (as documented) rake added a schema\_info  
table  
with version=0.

I’ve got three databases defined in database.yml using scripting I found  
in  
Rails Recipes #17.

I defined columns only for the development database.

Happily, rake went to the development database both to dump the schema  
and  
add the schema\_info table.

Question: How did rake decide to use that database rather than test or  
production?

Is it because development is specified first in the yml file?

Is it because development is the only one with tables?

Is it because there’s a setting somewhere that defaults to development  
but  
can be modified to target other databases?

I’m running WinXP-Pro/SP2, Ruby 1.8.2-15, Rails 1.1.4, MySQL 5.0.15-nt,  
SciTE 1.59, FireFox 1.2.0.7, Java JDK 1.5.0\_06

Thanks in Advance,

Richard

---

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [October 24, 2006, 8:38am UTC](https://www.ruby-forum.com/t/how-does-rake-decide-which-database-to-modify/73373/2 "2006-10-24T08:38:35Z")

</div>

Hi!

On Tue, Oct 24, 2006 at 02:20:13AM -0400, Richard L. wrote:

> Hi All,  
> […]  
> can be modified to target other databases?  
> Rails defaults to the development environment (and therefore the  
> development database). You can switch to production by setting the  
> RAILS\_ENV environment variable to ‘production’. The test evironment is  
> used automatically for running testcases.

You can, however, specify additional database connections in  
database.yml, and explicitly tell activerecord to use these:

class FromOtherDb \< ActiveRecord::Base  
establish\_connection configurations[‘otherdb’]  
end

Jens

–  
Jens Krämer  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [October 24, 2006, 8:40am UTC](https://www.ruby-forum.com/t/how-does-rake-decide-which-database-to-modify/73373/3 "2006-10-24T08:40:35Z")

</div>

Morning (i still haven’t had that cup of coffee)

I believe you set this using the RAILSENV=production parameter for rake,  
and that the default is development. I cannot find reference to this  
specifically at the moment - if anyone can point me to a link  
documenting the use of RAILSENV I will really appreciate it.

The command that I have used is:

rake db:migrate RAILSENV=production when migrating to production  
environment.

Ivor

---

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [October 24, 2006, 8:48am UTC](https://www.ruby-forum.com/t/how-does-rake-decide-which-database-to-modify/73373/4 "2006-10-24T08:48:37Z")

</div>

Hi Ivor and Jens,

Thanks for your responses. It’s 2:43am my time so I’m going to crash  
for the night. I’ll try all your approaches tomorrow.

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [October 25, 2006, 5:43am UTC](https://www.ruby-forum.com/t/how-does-rake-decide-which-database-to-modify/73373/5 "2006-10-25T05:43:32Z")

</div>

Hi Jens and Ivor,

Ivor, I used your RAILS\_ENV=test clause (not the underscore!) and it  
created my (empty) test database.

Jens,

I saved your input. I’m not ready for a more sophisticated approach at  
this time.

Thank you both very much for your responses. I couldn’t find any  
documention for this issue through Google searches.

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![rjlyders](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rjlyders](https://www.ruby-forum.com/u/rjlyders)\
**Post date:** [November 21, 2006, 5:11am UTC](https://www.ruby-forum.com/t/how-does-rake-decide-which-database-to-modify/73373/6 "2006-11-21T05:11:20Z")

</div>

Hi Ivor and Jens,

I saw your replies a month ago, for which I thank both of you. I just  
noticed today that I failed to acknowledge your response. Please accept  
this belated apology for that oversight.

Best wishes,  
Richard
