Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rake - halt on Rails migrate errors?

Is there a way to make rake halt execution when invoking the Rails migration tasks? Right now it runs straight through attempting each one. What I really want is to attempt drop, then attempt create, and if either of those are successful, then run migrate, then seed if that is successful, stop and display an error if any failures.

I've tried invoke on each task, testing the result but, that doesn't seem to be right either.

Thanks.

task :fresh_start => [
  'db:drop',
  'db:create',
  'db:migrate',
  'db:seed'] do
end
like image 261
evets Avatar asked Feb 24 '26 12:02

evets


1 Answers

By default Rake will stop at the first exception raised. For instance the following will never print "That".

task :this do
  puts "This"
  raise "Fail!"
end

task :that do
  puts "That"
end

task :default => [:this,:that]

Isn't that what you'd like ?

like image 56
Thibaut Barrère Avatar answered Feb 27 '26 01:02

Thibaut Barrère



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!