Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing db:test:prepare from another rake task

I'm trying to execute 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 invoke instead of execute doesn't help. It seems to work fine if I define it by itself:

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

When I run rake db:populate:development, all the tasks are run except for Rake::Task['db:test:prepare'].execute. There's no activity in the development log for that command, but it doesn't prevent the next task from running (starting the server). Usually, I see some SQL statements when I run db:test:prepare by itself.

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
like image 675
jrhorn424 Avatar asked Mar 19 '12 09:03

jrhorn424


1 Answers

I know this isn't the correct way of doing it, but I was having similar problems and ended up calling it using:

`rake db:test:prepare`

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

like image 158
maher.cs Avatar answered Oct 04 '22 14:10

maher.cs