0

I have a rakefile.rb in which there is task called add_latest_apps. This task creates some tables in a database if they have not been create using datamapper, scrapes some info from an xml feed and then puts the data in the tables. The problem is that I can't seem to get my rake task to run.

If I use the following command heroku run rake add_latest_apps then I get: rake aborted! no such file to load -- dm-sqlite-adapter which suggests to me that is trying to use the sqlite adapter even though it should be using the postgres adapter. What am I doing wrong?

rakefile.rb:

require 'open-uri'
require 'nokogiri'
require 'awesome_print'
require 'data_mapper'
require 'dm-postgres-adapter'
require 'pg'

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

class Company
    include DataMapper::Resource

    property :id, Serial
    property :company_name, String
    property :company_id, Text, :unique => true

    has n, :apps
end

class App
    include DataMapper::Resource

    property :id, Serial
    property :app_id, Integer
    property :bundle_id, Text
    property :app_name, Text
    property :company_name, Text
    property :created_at, DateTime
    property :rank, Integer

    belongs_to :company
end

DataMapper.finalize.auto_upgrade!

puts 'Database and tables created'

#Get App data from Apple
#Insert apps and companies into database

end

Gemfile:

source :rubygems
gem 'sinatra', '1.1.0'
gem 'thin'
gem 'nokogiri'
gem 'awesome_print'
gem 'data_mapper'
gem 'dm-postgres-adapter'
gem 'pg'

Please help!

1 Answers1

1

You need to set the DATABASE_URL environment variable.

The problem is with the line:

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

Here DataMapper looks for ENV['DATABASE_URL'], and if it isn’t set falls back to "sqlite3://#{Dir.pwd}/app.db", which causes it to try to load dm-sqlite-adapter.

Run heroku config to show your environment vars, it probaby won’t show DATABASE_URL. Check out the Heroku Postgres docs to determine what your URL should be. You may be able to do something like heroku pg:promote HEROKU_POSTGRESQL_GRAY_URL (although you’ll need to check what colour you should use).

matt
  • 78,533
  • 8
  • 163
  • 197
  • It seems like app does not actually have a database set up at the moment. I am trying to user `DataMapper.setup` to set it up. From what I have read about getting DataMapper to work with heroku the `ENV['DATABASE_URL']` should actually contain the address of my db (but of course it doesnt exist yet?!) – Stanislav Beremski Nov 25 '12 at 22:52