aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/railties
diff options
context:
space:
mode:
authorJay Hayes <ur@iamvery.com>2013-10-14 11:20:51 -0500
committerJay Hayes <ur@iamvery.com>2013-11-11 07:54:30 -0600
commit22f80ae57b26907f662b7fd50a7270a6381e527e (patch)
treefed6f18701451f9a7a7237cd1061f4f5e5181b43 /activerecord/lib/active_record/railties
parenta11ddbe55fd27f38e0085ee1210947e3d8f47220 (diff)
downloadrails-22f80ae57b26907f662b7fd50a7270a6381e527e.tar.gz
rails-22f80ae57b26907f662b7fd50a7270a6381e527e.tar.bz2
rails-22f80ae57b26907f662b7fd50a7270a6381e527e.zip
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
Diffstat (limited to 'activerecord/lib/active_record/railties')
-rw-r--r--activerecord/lib/active_record/railties/databases.rake36
1 files changed, 26 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake
index ecadb95a5d..26770bd951 100644
--- a/activerecord/lib/active_record/railties/databases.rake
+++ b/activerecord/lib/active_record/railties/databases.rake
@@ -8,31 +8,47 @@ db_namespace = namespace :db do
namespace :create do
task :all => :load_config do
- ActiveRecord::Tasks::DatabaseTasks.create_all
+ begin
+ ActiveRecord::Tasks::DatabaseTasks.create_all
+ rescue
+ exit(1)
+ end
end
end
desc 'Create the database from DATABASE_URL or config/database.yml for the current Rails.env (use db:create:all to create all databases in the config)'
task :create => [:load_config] do
- if ENV['DATABASE_URL']
- ActiveRecord::Tasks::DatabaseTasks.create_database_url
- else
- ActiveRecord::Tasks::DatabaseTasks.create_current
+ begin
+ if ENV['DATABASE_URL']
+ ActiveRecord::Tasks::DatabaseTasks.create_database_url
+ else
+ ActiveRecord::Tasks::DatabaseTasks.create_current
+ end
+ rescue
+ exit(1)
end
end
namespace :drop do
task :all => :load_config do
- ActiveRecord::Tasks::DatabaseTasks.drop_all
+ begin
+ ActiveRecord::Tasks::DatabaseTasks.drop_all
+ rescue
+ exit(1)
+ end
end
end
desc 'Drops the database using DATABASE_URL or the current Rails.env (use db:drop:all to drop all databases)'
task :drop => [:load_config] do
- if ENV['DATABASE_URL']
- ActiveRecord::Tasks::DatabaseTasks.drop_database_url
- else
- ActiveRecord::Tasks::DatabaseTasks.drop_current
+ begin
+ if ENV['DATABASE_URL']
+ ActiveRecord::Tasks::DatabaseTasks.drop_database_url
+ else
+ ActiveRecord::Tasks::DatabaseTasks.drop_current
+ end
+ rescue
+ exit(1)
end
end