Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect local rails app on my laptop to heroku database

It's pretty clear how to log into a heroku postgres database from psql locally: https://devcenter.heroku.com/articles/heroku-postgresql#external-connections-ingress

However, how does one setup database.yml locally to have a local rails instance talk to a heroku database?

like image 897
justingordon Avatar asked Sep 02 '13 10:09

justingordon


1 Answers

Try something like this

production:
  adapter: postgresql
  encoding: utf8
  database: DB_NAME_FROM_HEROKU
  username: USERNAME_FROM_HEROKU
  password: PASSWORD_FROM_HEROKU
  host: HOSTNAME_FROM_HEROKU # something like ec2-xxx-xx-xxx-xxxx.compute-1.amazonaws.com
  sslmode: require

to get the values, you need to run the following command

$ heroku pg:credentials:url

Then start your app in production env

$ rails s -e production

Since the database is hosted on the internet, expect lot of latency & general lack of responsiveness when working with running on local machine connected to database in the cloud.

PS: Ensure schema version of your local app matches exactly with remote database on heroku. Otherwise, there is a chance of dataloss when running migrations

like image 129
CuriousMind Avatar answered Sep 20 '22 10:09

CuriousMind