Reputation: 17812
We need to add the credentials of a database in database.yml
file under a different environment like remote_database
:
remote_database:
adapter:
encoding:
username:
...
And after adding all this, running the following command from the local terminal does the job:
RAILS_ENV=remote_database rails db:migrate
I'm trying to accomplish the same thing on Heroku. I have pushed the changes in config/database.yml
, and I'm trying to execute the following command:
RAILS_ENV=remote_database heroku run rake db:migrate
# or
heroku run rake db:migrate RAILS_ENV=remote_database
Seems like Heroku is completely ignoring RAILS_ENV
or the settings for remote_database
env in config/database.yml
file. Heroku always makes the changes in the regular database server connected with it that can be found at DATABASE_URL
.
Is there a way to run the migrations on a different database server through Heroku?
Upvotes: 1
Views: 181
Reputation: 468
Heroku injects database.yml
and overrides it completely with Rails under 4.1 version or overrides partially and allows a way for us to prevent overriding from Rails 4.1. Check the complete explanation about Rails database connection behaviour on Heroku article
So, in your case
url
key to your database.yml
as described in Active Record 4.1+ Escape Valve
section of above link.Upvotes: 1