1

I want to have 2 databases on one app. From Connecting Rails 3.1 with Multiple Databases I know how to set it up on my local machine and I know how to link to a different heroku database by changing the env vars. But since my database.yml looks like

development:
    adapter: postgresql
    database: first_database
log_development:
    adapter: postgresql
    database: second_database
production:
    adapter: postgresql

I do not know how to link the production app to two different database since the production gets the location of the database from DATABASE_URL env. I would need a DATABASE_URL2 and someway to tell production to use either env variable dynamically.

Community
  • 1
  • 1
sonnyhe2002
  • 2,091
  • 3
  • 19
  • 31

1 Answers1

0

Heroku rewrites the database.yml on deploy. It uses the DATABASE_URL environment variable to create a database.yml file for you. There is no way to add a second config value that will create a second entry in the generated database.yml.

There are ways to update the database configuration so that you can use database.yml locally and have it work the way you want in production on heroku. One way to inject your database.yml into the app is with the heroku_db_env gem:

https://github.com/skryl/heroku_db_env

You would move your database.yml with the additional database configurations to a a file specified by the gem and then you would be able to access them in production on Heroku just like you can locally.

Lukas Eklund
  • 6,068
  • 1
  • 32
  • 33
  • Even if i overwrite it how can i link it to another database? Is there a easy config change i can do without using someone's gem? – sonnyhe2002 Oct 25 '13 at 20:32
  • I'm not sure I understand what you mean when you say 'link'. I've tried to expand my answer to make it more clear. Are you asking how you switch between different databases in Rails? – Lukas Eklund Oct 28 '13 at 14:34
  • Your comment about heroku overwriting helped. – sonnyhe2002 Oct 28 '13 at 18:23