Are rails running locally with a remote Postgres connection?

Is there a way to configure the database.yml file for remote access to Heroku Postgres?

I'm having trouble understanding how Geroku, Rails and PG gem work.

Heroku seems to overwrite the database.yml file during deployment - is it possible to see the contents of this updated .yml file and use it locally?

+6
source share
3 answers

The following are the steps to access the Heroku database from local development:

  • Log in to your heroku account.

  • Go to this URL https://postgres.heroku.com/databases/ OR you can get the heroku db url by running this command in terminal: heroku pg:credentials:url

  • Select your application database.

  • You can see your heroku pg credentials:

     Host xxxxxxxxx.77777.amazonaws.com Database 42feddfddeee Username 44444444444 Port xxxx Password 777sfsadferwefsdferwefsdf 
  • gather more detailed information and add the evn file to your databse.yml file:

     adapter: postgresql host: < host > # HOST port: < port > # Port database: < database name > # Database Name username: < user_name > # User Name password: '< password >' # Password 

Reload the application,

Good luck..!!

+25
source

I'm a little newbie and may have misunderstood your question, but. Developed a ROR application using postgress database. Then uploaded to Heroku. I ran DB/Migrate/schema.rb to configure the remote Postgresql database.

From heroku's memory, run rake db:init (but I could be wrong). When I update the database in develpment in order to get the update in Heroku, I have to promote the code and run the launch of heroku rake db:migrate

From my config/dtabase.yml

 development: adapter: postgresql encoding: unicode database: di_development pool: 5 username: davidlee password: test: adapter: postgresql encoding: unicode database: di_test pool: 5 username: davidlee password: production: adapter: postgresql encoding: unicode database: di_production pool: 5 username: user password: 
  • and it works. I do not remember anything else.

Pierre

+1
source

I am not a postgres user, but this should work. You can modify database.yml to include host and port

 production: adapter: postgresql encoding: unicode database: di_production pool: 5 username: user password: host: heroku.host.name port: <postgres listen port> 

And, of course, you must enable server-side connectivity, both at the firewall and database levels.

Simple hack content #{Rails.root}/config/database.yml - this is to write code to load this yml into an object and then print it in the user interface

 DB_CONFIG = YAML.load(File.read("#{Rails.root}/config/database.yml", __FILE__)) puts DB_CONFIG["production"].inspect # or what ever method you want to print it 
+1
source

Source: https://habr.com/ru/post/956378/


All Articles