2
votes

My Rails 3 application uses Datamapper (dm-rails) as its main ORM, but it also needs to load ActiveRecord as it is required by a custom gem I'm using.

My problem is that the application now has two db:migrate rake tasks, and if I run rake db:migrate I get the following error:

rake aborted!
VERSION is required

Tasks: TOP => db:migrate => db:migrate:up
(See full trace by running task with --trace)

How do I make sure the ActiveRecord rake tasks are hidden so that I can execute the Datamapper migrate task? Using automigrate is not an option. Also, I want to use the actual db:migrate rake task, not another rake task, and not some console workaround.

Edit: My current workaround is to simply copy the Datamapper rake tasks under the db namespace and redefine them in a custom tasks file under a different namespace. This works. It seems redundant though and I would prefer a cleaner solution.

1
How did you do this?? Where are the Datamapper Rake tasks? I'm having the same issue.mltsy

1 Answers

0
votes

AHA! I don't know if this is the same problem you are having, but I found that in my application, the issue was in config/application.rb:

The line: require 'rails/all' should be replaced for Datamapper projects with:

# Pick the frameworks you want:
require 'action_controller/railtie'
require 'dm-rails/railtie'
# require 'action_mailer/railtie'
# require 'active_resource/railtie'
# require 'rails/test_unit/railtie'

The Datamapper rake task for db:migrate is actually included in dm-rails/railtie (not in dm-migrations). I believe the problem (the AR rake db task) is in active_resource/railtie, which you don't want if you're using DataMapper.

I don't know how rake decides which tasks to use, but I gather that it tries to run both tasks with the same name if both are defined.

In YOUR case, however, you might actually need active_resource/railtie, in which case the only solution I can think of aside from using another namespace like your workaround, would be to override the db:migrate rake task using something like this in a custom task file:

namespace :db do
  Rake::Task["db:migrate"].clear
  task :migrate do
    ...
  end
end