Wow I've been stuck on this one for days. I'm having trouble connecting to database.yml on Heroku. I'm on Cedar and ruby 1.9.2. My dev and test dbs are sqlite3 and the prod db is postgreSQL to cope with Cedar rules. Here is the code in my ruby script:
Rails.env.production? ? (env = "production") : (env = "development")
dbconfig = YAML::load(File.open('config/database.yml'))[env]
ActiveRecord::Base.establish_connection(dbconfig)
All goes well in local but when I push to Heroku, I get:
ArgumentError: syntax error on line 17, col 0: `adapter = uri.scheme'
from /usr/local/lib/ruby/1.9.1/syck.rb:135:in `load'
It looks like Heroku doesn't like my database.yml. Here's an overview:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: postgresql
encoding: unicode
database: foo
port: 5432
host: foobar.amazonaws.com
username: foo
password: bar
Managed PostgreSQL from HerokuHeroku Postgres delivers the world's most advanced open source database as a trusted, secure, and scalable service that is optimized for developers.
If you want to connect to Heroku Postgres, create a data source connection that correspond to the data source vendor. In this case, you plan to work with PostgreSQL, so you need to create a connection to PosgreSQL. DataGrip already include the necessary JDBC driver.
First, Heroku overwrites your config/database.yml
with its own Heroku-specific version. That's how Heroku automatically connects your application to its own postgresql databases. To tell Heroku about your own posgresql database, you should set up the correct config variables and you might as well omit the production database from your the config/database.yml
in your repository because Heroku will ignore it anyway.
Second, the config/database.yml
file is an ERB template for a YAML file. You must first run the file contents through Evaluated Ruby (ERB) before running the the output through YAML.
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