Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku and Datamapper problems

I can launch a basic app on Heroku, displaying a message with get '/'... works just fine. However, whenever I try to add sqlite with datamapper, the thing breaks down.

In order to see my app structure, check out the project on github. I've kept the code pretty bare-bones.

In the log from heroku I'm getting:

2011-06-26T21:28:36+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/dm-core-1.1.0/lib/dm-core/adapters.rb:163:in `require': no such file to load -- dm-postgres-adapter (LoadError)

The thing about this is that I'm not using postgres, so I'm confused why it is saying this.

like image 930
captDaylight Avatar asked Sep 12 '26 04:09

captDaylight


2 Answers

"The thing about this is that I'm not using postgres, so I'm confused why it is saying this."

You're using Heroku, so you are using Postgresql.

In your app.rb you have this line:

DataMapper::setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/notes.db")

which I'm guessing you got from the Heroku database docs. This line basically says "check for the environment variable 'DATABASE_URL', and if it's set use it as the database url, otherwise use the Sqlite url". Running locally this environment variable won't be set, so you'll use the Sqlite url, but on Heroku this will be set to something like (see the page linked above):

postgres://username:password@hostname/database

Datamapper will see that this is a Postgresql url, and try to require the postgres adapter, which isn't installed so will result in the error that you see.

The best solution would be to install Postgresql locally, so that your development and production environments are as similar as possible. If you can't do this, or don't want to, you can specify the Sqlite adapter locally, and the Postgres adapter in production. It'll look something like this in your Gemfile:

group :development do
  gem 'dm-sqlite-adapter'
end

group :production do
  gem 'dm-postgres-adapter'
end

If you do this you'll need to tell Heroku to which groups to leave out when installing gems, see the Heroku Gem Bunder docs.

like image 131
matt Avatar answered Sep 14 '26 03:09

matt


You are moving from sqlite to postgres-sql and thus you should include dm-postgres-adapter in your Gemfile (and install it ofcourse).

like image 20
Yet Another Geek Avatar answered Sep 14 '26 01:09

Yet Another Geek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!