5

For some reason, heroku tries to require dm-sqlite-adapter, even though it should use Postgres here. Note, that this happens when I open any URL - not during the git push itself.

I built a default facebook app.

The Gemfile:

source :gemcutter

gem "foreman"

gem "sinatra"
gem "mogli"
gem "json"
gem "httparty"
gem "thin"
gem "data_mapper"
gem "heroku"

group :production do
    gem "pg"
    gem "dm-postgres-adapter"
end

group :development, :test do
    gem "sqlite3"
    gem "dm-sqlite-adapter"
end

Datamapper setup:

# Setting up the database
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/data/mydatabase.db")

Relevant log fragment, when any URL is opened:

Starting process with command `bundle exec thin -R config.ru start -p 34984`
2012-01-18T15:11:55+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/adapters.rb:163:in `require': no such file to load -- dm-sqlite-adapter (LoadError)
2012-01-18T15:11:55+00:00 app[web.1]:   from /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/adapters.rb:163:in `load_adapter'

Tried related solutions, but with no help so far.

BTW: bundle install says Using do_postgres and Using dm-postgres-adapter. Am I missing something about Datamapper setup?

LordTwaroog
  • 1,738
  • 12
  • 23
  • Try setting a config var of `BUNDLE_WITHOUT` with the value of `development:test` and see what happens – Neil Middleton Jan 18 '12 at 15:40
  • I guess it's already run when I issue `git push heroku master`: `Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment` – LordTwaroog Jan 18 '12 at 15:44
  • Can you use Postgres locally? It's really a good idea: http://www.12factor.net/dev-prod-parity – Neil Middleton Jan 18 '12 at 15:51
  • Nice site, haven't seen this before. TBH, the whole point was to make a mock-up application, making use of the simplest path. Now I'm just wasting time tinkering with dm adapters, instead of getting things done. – LordTwaroog Jan 18 '12 at 15:56
  • 3
    This suggests the `DATABASE_URL` environment variable somehow isn't set. Have you removed it? Does it show up when you run `heroku config`? – matt Jan 18 '12 at 16:01
  • That was a brilliant suggestion! Details in the answer. – LordTwaroog Jan 18 '12 at 16:13

2 Answers2

9

Well, too many Rails apps on Heroku, I took the shared db presence for granted. heroku config showed neither DATABASE_URL or SHARED_DATABASE_URL set.

Issuing heroku addons:add shared-database:5mb solved the problem.

Strange, that the db wasn't automatically added, despite having 'pg' gem in Gemfile.

Quote from http://devcenter.heroku.com/articles/cedar:

A Heroku shared PostgreSQL database (shared-database:5mb) will be automatically added to your app in any of the following cases:

  • The app is a Rails application
  • The pg gem is specified in the Gemfile
matt
  • 78,533
  • 8
  • 163
  • 197
LordTwaroog
  • 1,738
  • 12
  • 23
3

Try doing DataMapper.setup(:default, ENV['DATABASE_URL'] || 'postgres://user:password@hostname/data/mydatabase.db') instead. Heroku is probably looking at the protocol, and therefore requiring SQLite’s dependencies.

Cesar Figueroa
  • 214
  • 2
  • 9
  • I thought this as well, but I changed my code to wrap my code in configure statements and it still did the same thing.`configure :development do DataMapper.setup(:default,"sqlite3://#{Dir.pwd}/recall.db") end configure :production do DataMapper.setup(:default, ENV['DATABASE_URL']) end` Also, I would assume the snippet reads `ENV['DATABASE_URL'] = true` and doesn't evaluate the RHS of the or statement. – Christos Hrousis Apr 10 '14 at 10:28