0

Are Heroku add-ons application specific, or can they be shared among several apps if you have them?

In other words if I have 5 separate apps in my account and I want $200/month Ronin Postgre DB add-on, and the WebSolr Silver $20 /month, would all 5 of my apps have access to them for the $220 per month? Or do you need separate add-ons for each individual app?

Frank
  • 714
  • 1
  • 9
  • 21

1 Answers1

0

Yes, you can share DB instances between applications - infact you don't even need to be using the Ronin addon, you can do it with the included PG - see this thread where I put forward a solution for doing this by using the same DB url in the second application as the first.

When you addons heroku typically write a bunch of heroku config variables for your app which they then use in files they write - eg database.yml - the actual database.yml file heroku write into your application is:

<%

require 'cgi'
require 'uri'

begin
  uri = URI.parse(ENV["DATABASE_URL"])
rescue URI::InvalidURIError
  raise "Invalid DATABASE_URL"
end

raise "No RACK_ENV or RAILS_ENV found" unless ENV["RAILS_ENV"] || ENV["RACK_ENV"]

def attribute(name, value)
  value ? "#{name}: #{value}" : ""
end

adapter = uri.scheme
adapter = "postgresql" if adapter == "postgres"

database = (uri.path || "").split("/")[1]

username = uri.user
password = uri.password

host = uri.host
port = uri.port

params = CGI.parse(uri.query || "")

%>

<%= ENV["RAILS_ENV"] || ENV["RACK_ENV"] %>:
  <%= attribute "adapter",  adapter %>
  <%= attribute "database", database %>
  <%= attribute "username", username %>
  <%= attribute "password", password %>
  <%= attribute "host",     host %>
  <%= attribute "port",     port %>

<% params.each do |key, value| %>
  <%= key %>: <%= value.first %>
<% end %>

I would imagine the same thing is going to be possible with websolr if you add it to a single instance and then see what config variables are set and set the same in the other applications. I would also imagine that this is unsupported by Heroku and they would actively discourage you from doing it however.

Community
  • 1
  • 1
John Beynon
  • 37,398
  • 8
  • 88
  • 97
  • Thanks for the info on sharing the database. I went ahead and contacted Heroku and was told that in general most add-ons are app specific, but that the databases could be shared, although not the WebSolr add-on. As you mentioned, there might be a way, but they probably don't want that. – Frank Sep 19 '11 at 20:37