2

I've made 2 apps, App A and App B. App A's sole purpose is to allow users to sign up and App B's purpose is to take select users from App A email them. Since App A & B were created independently & are hosted in 2 separate Heroku instances, how can App B access the users database in App A? Is there a way to push certain relevant rows from App A to App B?

3
  • i don't know if active resource will help you out here. the expensive option would be to use mongohq as your database - it works well with heroku i'm told - I would think that in the future, heroku will give you more power over the database Commented Mar 10, 2010 at 0:38
  • This sounds like it's against herokus terms of service. Using multiple instances to circumvent free plan limitations isn't allowed. Commented May 10, 2011 at 18:47
  • Here the official documentation: devcenter.heroku.com/articles/… Commented May 30, 2019 at 9:45

6 Answers 6

4

There is currently no way of sharing databases between Heroku apps.

You might be able to use the Amazon RDS add-on to run a dedicated MySQL instance.

The alternative is going to be creating an API and pushing data between the apps. You can run a background process to push the data in and out.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks Toby, I was thinking that an API would be the best way to go about creating this. Only problem is, I don't know how to create an API. Any good online guides?
Have a look at using ActiveResource - you can have your controllers accept and produce XML and then tie that to a model. Works really well.
3

You can connect several Heroku instances on the same shared PostgreSQL database, given by the shared-database:5mb free add-on on Heroku.

On the instance on which you have the database, type:

$ heroku config

This will show a lot of settings, in which you'll see something like this:

DATABASE_URL => postgres://fbksgiuqlv:[email protected]/fbksgiuqlv

This is the database connection string that your instances will be using.

Then on the other instances, overwrite the DATABASE_URL config variable by typing:

$ heroku config:add DATABASE_URL=your_new_connection_string

1 Comment

2

So tinkered a little around and did as below and it worked

prompt$ heroku console
Ruby console for your-app.heroku.com
>> dbconfig = YAML.load(File.read('config/database.yml'))
=> {"production"=>{"encoding"=>"unicode", "port"=>5432, "adapter"=>"postgresql", "username"=>"xxxxxxxxxxxxxx", "database"=>"xxxxxxxxxxxxx", "host"=>"kklasfdsfjsfdsfsd.fsdf.dsfdsf", "password"=>"xxxxxxxxxxxxxxxxxx"}}
puts dbconfig.to_yaml
--- 
production: 
  encoding: unicode
  port: 5432
  adapter: postgresql
  username: xxxxxxxxxxx
  database: xxxxxxxxxxxxxxx
  host: ec2-50-2323kskdsakd231.amazonaws.com
  password: xxxxxxxxxxxxxx

Then copy and paste the yaml to a connection for the other DB

and it works!!! For me!!!

Comments

1

I was looking into this as well and I noticed that it seems like it is now possible to actually do this.

See: http://newsletterer.heroku.com/2011/07 ("did you know" section at the bottom)

Basically you set up one app, retrieve the app database url, and add that url to the config of the other app, like so:

$ heroku config | grep DATABASE_URL  --app sushi
DATABASE_URL   => postgres://lswlmfdsfos:[email protected]/ldfoiusfsf

Then, set the DATABASE_URL for new apps to this value:

$ heroku config:add DATABASE_URL=postgres://lswlmfdsfos:[email protected]/ldfoiusfsf --app sushi-analytics
Adding config vars: DATABASE_URL => postgres://lswlm...m/ldfoiusfsf
Restarting app... done, v74.

That's it — now both apps will share one database.

I haven't tried this yet, but I am about to give it a shot, as I too was thinking about splitting an existing app into two apps. Let's hope this actually works!

Comments

0

Heroku actually overwrites the database.yml file that you have checked in, you can verify this by using the "heroku shell" command and typing cat config/databse.yml

They make up a bunch of random stuff that is used per application. I don't believe its possible to stop them from doing that.

1 Comment

I think it should be "cat config/database.yml"
-3

You might be able to do this if you use schemas with PostgreSQL.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.