# Question about environments and rake

**URL:** <https://www.ruby-forum.com/t/question-about-environments-and-rake/119069>\
**Category:** Rails\
**Created:** [November 2, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/question-about-environments-and-rake/119069 "2007-11-02T20:51:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 2, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/question-about-environments-and-rake/119069/1 "2007-11-02T20:51:03Z")

</div>

Hi,

Short version:  
How do I specify an environment (as in, development, production, or in  
my case, a custom environment) to the command ‘rake db:migrate?’

Long version:  
A friend and I are putting together a web app using Ruby on Rails. We  
wanted to both have our own development instances running to play  
with, each that could be configured slightly differently. So what we  
ended up doing was creating two environments – user1\_development, and  
user2\_development – with their own environment files, and their own  
listings in config/databases.yml. We wanted each of these instances to  
have their own databases, so the entry in databases.yml for  
user1\_development, for instance, is identical to that for the  
“development” environment, except instead of the database being named  
“projectname\_development” it’s named “projectname\_user1\_development.”

We’re using mongrel and each have our own mongrel\_cluster.yml files  
that specify our respective environments, so that all works fine.

The problem is with rake db:migrate. I cannot figure out how to get  
rake to run in a custom environment; so, for instance, when I do a  
rake db:migrate, I don’t know how to get it to migrate database  
“projectname\_user1\_development” instead of “projectname\_development.”  
Does anyone have any idea how to do this?

Thanks very much,  
Paul Eastlund

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 2, 2007, 9:46pm UTC](https://www.ruby-forum.com/t/question-about-environments-and-rake/119069/2 "2007-11-02T21:46:35Z")

</div>

> Short version:  
> How do I specify an environment (as in, development, production, or in  
> my case, a custom environment) to the command ‘rake db:migrate?’

rake db:migrate RAILS\_ENV=production

> Long version:  
> A friend and I are putting together a web app using Ruby on Rails. We  
> wanted to both have our own development instances running to play  
> with, each that could be configured slightly differently. So what we  
> ended up doing was creating two environments – user1\_development, and  
> user2\_development – with their own environment files, and their own  
> listings in config/databases.yml. We wanted each of these instances to

Is the only difference b/n your sites database.yml? Is so, why not  
commit  
a database.yml-sample and then svn-ignore database.yml and just set it  
to  
what you want.

That works well for us… and allows us to all use “development”…

Not saying you have to, just pointing out another option.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 2, 2007, 9:55pm UTC](https://www.ruby-forum.com/t/question-about-environments-and-rake/119069/3 "2007-11-02T21:55:57Z")

</div>

On Nov 2, 2007 7:03 PM, Philip H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Short version:  
> > How do I specify an environment (as in, development, production, or in  
> > my case, a custom environment) to the command ‘rake db:migrate?’
> 
> rake db:migrate RAILS\_ENV=production

Thanks for the tip! This worked like a charm.

> Is the only difference b/n your sites database.yml? Is so, why not commit  
> a database.yml-sample and then svn-ignore database.yml and just set it to  
> what you want.
> 
> That works well for us… and allows us to all use “development”…
> 
> Not saying you have to, just pointing out another option.

Thanks for the suggestion. No, there’s also some minor differences  
between  
our config/environments files. The chief other issue was this: I want to  
have a non-secure page that contains a form that the user can fill  
secure  
data into. In HTML terms, this just means that the form tag needs a URL  
that  
starts with “https://” but there’s no way to specify the protocol  
without  
specifying the domain, which means each of our apps needs to know the  
domain  
it’s being hosted at. Since Rails has no knowledge of this already, and  
the  
two apps are at slightly different domains, we put this data in the  
environment files – so config/environments/user1.rb has the line  
DOMAIN="  
[user1.oursite.com](http://user1.oursite.com)", for instance. It’s a little bit of a hack, but we  
searched around online and couldn’t find a prettier solution. Please let  
me  
know if you have one.

-Paul

–  
Paul Ragnar Eastlund

Me: (relating a joke) “…so I said, ‘I’m working at Google. I’m the guy  
who  
frantically does research when you type in a query.’”  
Lorraine: “Oh.” (long pause) “But is that really what you do?”  
Sharon: “…And now, the joke is on you.”
