When my app is built on Heroku it says
Writing config/database.yml to read from DATABASE_URL
What does that mean? Is this new to the Cedar stack?
I have a Rack app. My config.ru
used to work on Barmy Bamboo stack:
#!/usr/bin/ruby
environment = ENV['DATABASE_URL'] ? 'production' : 'development'
require './pb.rb'
dbconfig = YAML.load(File.read('config/database.yml'))
Pb::Models::Base.establish_connection dbconfig[environment]
Pb.create if Pb.respond_to? :create
run Pb
On my own computer it would read my local config/database.yml
(which isn't commited to source control)
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
And on Heroku it would read Heroku's database.yml
. Inspecting it now on Cedar heroku run cat config/database.yml
, it appears to be a Ruby file , and not yml. Is this change explained anywhere?
When you push your app to Heroku, if you have a config
directory, the Ruby build pack writes a new database.yml
file, and produces the message you see when it does.
Rails runs this file through ERB when loading it, to allow various dynamic options. Heroku make use of this, producing an ERB file that read the DATABASE_URL
environment variable and creates the approppriate .yml
file pointing to that database.
I’m assuming that in the case of Bamboo the database.yml
that was created was a plain Yaml file pointing to your database (I can’t find any reference).
To get your app working on Cedar, you need to run the file through ERB in the same way as Rails does. Change this:
dbconfig = YAML.load(File.read('config/database.yml'))
to
require 'erb'
dbconfig = YAML.load(ERB.new(File.read('config/database.yml')).result)
If your local database.yml
is just plain yaml, running through ERB like this should be a no-op, and it will pick up the right values on Heroku.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With