Hacker News new | ask | show | jobs
Access the database of a heroku application from another heroku application (debugarea.com)
9 points by geoscripting 4826 days ago
4 comments

Addon providers (of which heroku postgres is) can change the the config var they set at any time. Simply copy-and-pasting creds from one app to another will leave the second app broken when those creds are changed.
Heroku Postgres is now a standalone product (You can purchase postgres databases without a heroku app) so they won't change the URI for a database out from under you.
For the standalones we give more warning, sure. But not for the ones attached to apps.
establish_connection will automatically parse a postgres URI for you, so you can just use:

    ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
This also works for class-specific databases:

    class Photo < ActiveRecord::Base
      establish_connection(ENV['PHOTOS_DATABASE_URL'])
    end
If this is being presented as a security problem, know that this is a non-issue. This is intended behavior; Heroku config vars are considered secret. If this is just showing off that you can run multiple apps from a single database, then, yes, that too should have been clear.
Yeah, don't really get this, it's basically saying, if you have the username, password and hostname for a database, you can access it...
I wrote this rails app that lets you look at the schemas of your other rails apps. Might be interesting to incorporate this into it.