I want to access the database of an app from another Heroku app. Is that possible in the shared database?
相关问题
- Eager-loading association count with Arel (Rails 3
- How to specify memcache server to Rack::Session::M
- Connecting Python to a Heroku PostgreSQL DB?
- rails/heroku migrating from gem to toolbelt
- Using runtime env with React and heroku
相关文章
- Django/Heroku: FATAL: too many connections for rol
- “No explicit conversion of Symbol into String” for
- Rspec controller error expecting <“index”> but
- Factory_girl has_one relation with validates_prese
- Heroku Web Server Won't Start Locally
- Rails: Twitter Bootstrap Buttons when visited get
- is there a “rails” way to redirect if mobile brows
- Got ActiveRecord::AssociationTypeMismatch on model
UPDATED
Originally, this answer stated that although this was possible with a few tricks, it was strongly discouraged. This was based on advice on the Heroku developer support website. However, recently Heroku issued a communication specifically describing how to achieve this, and have watered down their advice on the developer site. The complete text of this section of their e-mail is included below:
Just as a point of reference, Heroku's original advice was to create and use an API to access data remotely. My personal view is that overall, for many situations this is good advice, (i.e. better than just connecting multiple application to the same DB) although I can see situations where that'd be more trouble than it's worth.
UPDATE
As per comments on this answer, it's worth noting that Heroku do reserve the right to change database URLs as required. If this occurs, it will cause your secondary connections to fail, and you'll need to update the URLs accordingly.
See Heroku reference: https://devcenter.heroku.com/categories/heroku-postgres
I received this in the Heroku newsletter recently. I'm emailing them to find out if it really is an approved usage.
The Amazon RDS plugin works well for this. Multiple apps can share the same RDS instance.
You have the flexibility to have them share tables or avoid table name collision using the active_record.table_name_prefix.
Late-breaking answer to the pertinent question!
Heroku officially supports a better/graceful solution by the way of their addon framework now. It is described in their latest newsletter on how to share addons between apps. Below are the snippets mentioned in the writeup:
Link: expanding_the_power_of_add_ons
as far as I know it is possible - you'll have to look at the heroku config variables for your app with the DB and then set the database_url on the app that wants to share the database to the same value. Kinda off track though and as to how supported it is I don't know.
EDIT Just to set my mind at rest I've spun up two apps on Heroku - a simple scaffold 'post' with a title.
http://evening-spring-734.heroku.com/posts is the master
http://electric-galaxy-230.heroku.com/posts - is the slave
So posts created on either will be written to the database URL of evening-spring-734.
All I've done is use heroku config to get the DATABASE_URL of evening-spring-734 and then set the same value into the DATABASE_URL of electric-galaxy-230.
You could end up with some fruity DB race conditions but it is definitely possible to do.
Magic huh?