New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using ActiveRecord Rake tasks out of Rails #11609

xcambar opened this Issue Jul 26, 2013 · 7 comments


None yet
7 participants

xcambar commented Jul 26, 2013

I'm building a Grape+ActiveRecord API, and I've been running into a strange issue while trying to use ActiveRecord Rake tasks into this project.

Here's a snippet of the Rakefile:

require 'rake'
require 'active_record'

include ActiveRecord::Tasks
DatabaseTasks.database_configuration = YAML::load('./config/database.yml'))
DatabaseTasks.db_dir = 'db'

And I get the following error when running rake -T:

database configuration does not specify adapter
/Users/xav/code/ruby/incase/server2/Rakefile:7:in `<top (required)>'

I (think I) have read carefully the doc in though.

After some quick investigation, it appears that the line 52 of connection_specification.rb ( checks for a symbol in the Hash:

raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)
  1. The keys in the parsed YAML file are all strings. So the documentation does not make a valid example (unless I'm wrong).
  2. Even when I convert the hash so the keys are symbols, I still have the same error.

What do you think? Is that a PEBKAC or a bug?


This comment has been minimized.


dmathieu commented Jul 26, 2013

create_current calls each_current_configuration, which relies on ActiveRecord::Base.configurations, not ActiveRecord::Tasks::DatabaseTasks.database_configuration.

You're apparently just not defining the configuration at the right place.

@drogus: you implemented this in d1d7c86, but apparently missed some configuration uses. Was that on purpose?


This comment has been minimized.

miry commented Jul 26, 2013

@xcambar ActiveRecord::Base.configurations = DatabaseTasks.database_configuration


This comment has been minimized.


drogus commented Jul 26, 2013

Damien is right about providing the configuration. I intentionally left out
the configuration part, because it's up to the application to provide the
config and it's up to the application when to do it. Maybe it could be
improved to handle some kind of "default" use case, but I'm hesitant to
make it any more complicated for now.

Here is the gist with an example Rakefile, which you could use to run AR
rake tasks:, so basically the part
which you're missing is :environment task, which sets the configuration
and initializes the connection.

I started adding info about it in the AR guide, I will push it later today.

On Fri, Jul 26, 2013 at 11:54 AM, Michael Nikitochkin <> wrote:

@xcambar pls provide the content of

Reply to this email directly or view it on GitHub

Piotr Sarnacki


This comment has been minimized.


dmathieu commented Jul 26, 2013

Since this is not a bug, I believe the issue can be closed.


This comment has been minimized.


robin850 commented Jul 26, 2013

Agree with @dmathieu since @drogus is working on the documentation.


This comment has been minimized.

xcambar commented Jul 26, 2013

Works perfectly!

Thanks for helping


This comment has been minimized.

kpassapk commented Oct 6, 2013

Thanks @drogus, I was having similar issues :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment