Sinatra + Heroku + Datamapper deploy issues with dm-sqlite-adapter

*爱你&永不变心* 提交于 2019-12-04 13:06:44

问题


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?


回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/8912738/sinatra-heroku-datamapper-deploy-issues-with-dm-sqlite-adapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!