23
Apr
12

access the database of a heroku application from another heroku application



First thing you have to do is find out the DATABASE_URL of the app you’re interested in. Run heroku config –app your_app to get it. Then, in the other app, run this:

heroku config:add DATABASE_URL=whatever_the_result_of_the_first_command_was

Establish an ActiveRecord connection:


  db = URI.parse(ENV['DATABASE_URL'] || 'postgres://localhost/mydb')

  ActiveRecord::Base.establish_connection(
              :adapter  => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
              :host     => db.host,
              :username => db.user,
              :password => db.password,
              :database => db.path[1..-1],
              :encoding => 'utf8'
   )

Advertisements

0 Responses to “access the database of a heroku application from another heroku application”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Blog Stats

  • 221,294 hits

%d bloggers like this: