Tuesday, August 21, 2012

invalid DATABASE_URL error when I deploy padrino + mongoid to heroku

Problem


I deployed my padrino apps to heroku but could not be started. and I saw "invalid DATABASE_URL" when I run "heroku run padrino console"

the exception was thrown at this line

Padrino.before_load do
  Mongoid.load!(File.join(Padrino.root,"config/database.yml"))
end

Troubleshooting


I suspected that something wrong with my database configuration file, so I double checked all the configuration files, everything's fine. All the env and (list by running 'heroku config') looks fine. Then I tried run the remote console and try to repeat the problem by requiring and executing the Mongoid methods directly.


Real Cause


I found out that the program keep reading from database.yml and the content was totally different from my database.yml. It was something like erb script reconstructing the login credential for a PostgreSQL connection.
It turned out that, although the postgreSQL shared database add-on was no longer activated on heroku be default, heroku still tried to generate the config/database.yml which OVERWRITTEN my config/database.yml.

Solution


simple.
just rename my database.yml to mongoid.yml and then change the Mongoid.load! to

Mongoid.load!(File.join(Padrino.root,"config/mongoid.yml"))

1 comment: