Custom db rake task gives 'development database not configured'

Hi all,
I’m trying to write a simple custom rake task to easily delete some
database records. However when I run it, I get an error ‘development
database is not configured’.

Here’s the code:
lib/tasks/custom.rake

require ‘activerecord’

namespace :db do
task :delete_sessions do
sessions = ENV[‘sessions’].split(’,’).collect! {|n| n.to_i}
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
for session in sessions do
ActiveRecord::Base.connection.execute(“DELETE FROM pool_sessions
WHERE pool_session_id=#{session};”)
end
end
end

And how I call it:

$ rake db:delete_sessions sessions=1,2
(in )
rake aborted!
development database is not configured

(See full trace by running task with --trace)

If I change RAILS_ENV to test or production I get parallel results.

I can still do other rake db tasks, such as drop, create, and migrate,
so I know that my config/database.yml is OK.

Any ideas? Thanks.
-David


David van Geest
Software Engineer
Spindance, Inc.
616.355.7000 x113

On Apr 26, 4:34 pm, David van Geest [email protected] wrote:

I can still do other rake db tasks, such as drop, create, and migrate,
so I know that my config/database.yml is OK.

Any ideas? Thanks.

Taking a look at databases.rake in rails itself, I think you want to
depend on the :load_config task so that your database.yml file is
actually loaded

Fred

Frederick C. wrote:

actually loaded

Fred

That’s the ticket. Thanks!


David van Geest
Software Engineer
Spindance, Inc.
616.355.7000 x113