Archive for the 'heroku' Category

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



Blog Stats

  • 225,274 hits