I am trying to deploy a small app on heroku. Deploying works fine, and it runs without a problem in my local environment. However, in production the app crashes immediately, throwing an "Application Error".
I suspect the problem is the fact that no database tables are getting created (when I look at the statistics on heroku/psql it says Tables: 0). I have no idea why though. The code is on github https://github.com/valentin-zambelli/kanban-for-students/tree/master
Snapshot from my app.rb file
require 'sinatra'
require 'haml'
require 'data_mapper'
require "date"
require "pg"
class Note
include DataMapper::Resource
property :id, Serial
property :content, Text, :required => true
property :status, Integer
property :created_at, DateTime
property :updated_at, DateTime
end
configure do
DataMapper.setup(:default, ENV['postgres://coeastaxltnwlx:JnO2uo9HyracxQQ86n49u-FlzE@ec2-54-204-40-96.compute-1.amazonaws.com:5432/d7n7n4iggsqnke'] || "sqlite3://#{Dir.pwd}/development.db")
DataMapper.finalize.auto_upgrade!
end
and from the gem file
source "https://rubygems.org"
ruby "2.1.2"
gem "sinatra"
gem "thin"
gem "haml"
gem 'data_mapper'
gem "pg"
gem "dm-postgres-adapter"
Here are the last few error messages I get from $ heroku logs
2014-10-27T10:55:48.591707+00:00 heroku[web.1]: Process exited with status 1
2014-10-27T10:55:48.600652+00:00 heroku[web.1]: State changed from starting to crashed
2014-10-27T10:55:55.697970+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-waters-2400.herokuapp.com request_id=1a3e9d90-c9f2-4cdc-842b-55d3152089ba fwd="83.64.207.92" dyno= connect= service= status=503 bytes=
2014-10-27T10:55:56.508412+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=murmuring-waters-2400.herokuapp.com request_id=d83bdf15-c09c-4919-ab05-30b862199323 fwd="83.64.207.92" dyno= connect= service= status=503 bytes=
2014-10-27T10:56:06.872347+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-waters-2400.herokuapp.com request_id=2e4a1984-c1ea-4234-8331-3f6a6f217137 fwd="54.161.222.26" dyno= connect= service= status=503 bytes=
Any help is much appreciated!
I think the problem is in the DataMapper.setup
method call. You are looking up the database URL in the ENV
object (collection of environment variables) which is good, but instead of passing the name of environment variable (DATABASE_URL
) you have copied the actual URL into there. You should avoid putting this in your code.
Try something like:
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db")