Running db: test: preparing from another rake task

I am trying to run rake db:test:prepare from another task.

 namespace :db do namespace :populate do desc "Seed development database" task development: :environment do puts "Kill local server" %x{ ps xauwww | grep -i --regex="[t]hin" | awk '{print $2}' | xargs kill } puts "Resetting development database" Rake::Task['db:reset'].execute puts "Migrating development database" Rake::Task['db:migrate'].execute puts "Populating development database" Rake::Task['db:populate'].execute puts "Pepare test database" Rake::Task['db:test:prepare'].execute puts "Start local server" system 'thin -d start' end … end 

Using a call instead of executing does not help. It seems to work fine if I define it myself:

 task example: :environment do Rake::Task['db:test:prepare'].execute end 

When I run rake db:populate:development , all tasks are executed except for Rake::Task['db:test:prepare'].execute . There is no activity for this command in the development log, but this does not prevent the next task from starting (server start). I usually see some SQL statements when I run db:test:prepare myself.

Notes:

 $ rails -v Rails 3.2.2 $ ruby -v ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0] $ uname -a Darwin hook 11.3.0 Darwin Kernel Version 11.3.0: Thu Jan 12 18:47:41 PST 2012; root:xnu-1699.24.23~1/RELEASE_X86_64 x86_64 
+7
source share
3 answers

I know this is not the right way to do this, but I had similar problems and called him using:

 `rake db:test:prepare` 

This is the only method that seemed to work for me.

+1
source

Try Rake::Task['db:test:prepare'].invoke .execute instead of .execute to run dependent tasks first. But it only causes a task, unless it is called first.

Contact: this

0
source

The Rake task probably falls into this line https://github.com/rails/rails/blob/master/activerecord/lib/active_record/railties/databases.rake#L364 and ActiveRecord::Base.configurations empty. This variable is set here https://github.com/rails/rails/blob/master/activerecord/lib/active_record/railties/databases.rake#L5 (see https://github.com/rails/rails/ blob / 370e1ad3f1f30f955bd781f0ecd113409b8ccf8f / activerecord / lib / active_record / tasks / database_tasks.rb # L21 ).

Is there a chance your database.yml missing the current environment or something else will clear the configuration?

0
source

All Articles