From 22f80ae57b26907f662b7fd50a7270a6381e527e Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Mon, 14 Oct 2013 11:20:51 -0500 Subject: Explicitly exit with status "1" for create and drop failures * A non-zero exit status allows subsequent shell commands to be chained together such as: `rake db:reset test:prepare && rspec && cap deploy` (if you're feeling brave :) * Any exceptions raised during the `create` and `drop` tasks are caught in order to print a "pretty" message to the user. Unfortunately doing so prevents rake from aborting with a non-zero exit status to the shell. * Therefore we re-raise the exceptions after the "pretty" message and re-catch them in the task. * From the task we explicitly exit with a non-zero status. This method was chosen (rather than just letting rake fail from the exception) so that the backtrace is suppressed and the output to stderr is unchanged. * Update activerecord CHANGELOG --- activerecord/lib/active_record/tasks/database_tasks.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'activerecord/lib/active_record/tasks') diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index b91bbeb412..8acf0bd520 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -69,9 +69,11 @@ module ActiveRecord class_for_adapter(configuration['adapter']).new(*arguments).create rescue DatabaseAlreadyExists $stderr.puts "#{configuration['database']} already exists" + raise rescue Exception => error $stderr.puts error, *(error.backtrace) $stderr.puts "Couldn't create database for #{configuration.inspect}" + raise end def create_all @@ -95,6 +97,7 @@ module ActiveRecord rescue Exception => error $stderr.puts error, *(error.backtrace) $stderr.puts "Couldn't drop #{configuration['database']}" + raise end def drop_all -- cgit v1.2.3