David van Geest
2010-Apr-26 15:34 UTC
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 <rails root>) 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Apr-26 16:45 UTC
Re: custom db rake task gives ''development database not configured''
On Apr 26, 4:34 pm, David van Geest <dav...-IRGzu59+v81l57MIdRCFDg@public.gmane.org> 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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David van Geest
2010-Apr-26 21:46 UTC
Re: Re: custom db rake task gives ''development database not configured''
Frederick Cheung wrote:> On Apr 26, 4:34 pm, David van Geest <dav...-IRGzu59+v81l57MIdRCFDg@public.gmane.org> 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 >That''s the ticket. Thanks! --- David van Geest Software Engineer Spindance, Inc. 616.355.7000 x113 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.