From 728096542aef4820440b2d758cfdc579b399f1e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 19 Nov 2013 13:07:28 -0200 Subject: Revert "Explicitly exit with status "1" for create and drop failures" This reverts commit 22f80ae57b26907f662b7fd50a7270a6381e527e. See https://github.com/rails/rails/commit/22f80ae57b26907f662b7fd50a7270a6381e527e#commitcomment-4640676 Conflicts: activerecord/CHANGELOG.md --- activerecord/CHANGELOG.md | 4 --- .../lib/active_record/railties/databases.rake | 36 ++++++---------------- .../lib/active_record/tasks/database_tasks.rb | 3 -- activerecord/test/cases/tasks/mysql_rake_test.rb | 4 +-- .../test/cases/tasks/postgresql_rake_test.rb | 8 ++--- activerecord/test/cases/tasks/sqlite_rake_test.rb | 12 ++------ 6 files changed, 16 insertions(+), 51 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 0bef057836..ed16d68253 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -2,10 +2,6 @@ *Edo Balvers* -* Exit with non-zero status for failed database rake tasks. - - *Jay Hayes* - * Added `ActiveRecord::Base.to_param` for convenient "pretty" URLs derived from a model's attribute or method. Example: diff --git a/activerecord/lib/active_record/railties/databases.rake b/activerecord/lib/active_record/railties/databases.rake index 3ca66223b6..52b3d3e5e6 100644 --- a/activerecord/lib/active_record/railties/databases.rake +++ b/activerecord/lib/active_record/railties/databases.rake @@ -8,47 +8,31 @@ db_namespace = namespace :db do namespace :create do task :all => :load_config do - begin - ActiveRecord::Tasks::DatabaseTasks.create_all - rescue - exit(1) - end + ActiveRecord::Tasks::DatabaseTasks.create_all 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 - begin - if ENV['DATABASE_URL'] - ActiveRecord::Tasks::DatabaseTasks.create_database_url - else - ActiveRecord::Tasks::DatabaseTasks.create_current - end - rescue - exit(1) + if ENV['DATABASE_URL'] + ActiveRecord::Tasks::DatabaseTasks.create_database_url + else + ActiveRecord::Tasks::DatabaseTasks.create_current end end namespace :drop do task :all => :load_config do - begin - ActiveRecord::Tasks::DatabaseTasks.drop_all - rescue - exit(1) - end + ActiveRecord::Tasks::DatabaseTasks.drop_all 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 - begin - if ENV['DATABASE_URL'] - ActiveRecord::Tasks::DatabaseTasks.drop_database_url - else - ActiveRecord::Tasks::DatabaseTasks.drop_current - end - rescue - exit(1) + if ENV['DATABASE_URL'] + ActiveRecord::Tasks::DatabaseTasks.drop_database_url + else + ActiveRecord::Tasks::DatabaseTasks.drop_current end end diff --git a/activerecord/lib/active_record/tasks/database_tasks.rb b/activerecord/lib/active_record/tasks/database_tasks.rb index 0b6a49ac85..be7d496d15 100644 --- a/activerecord/lib/active_record/tasks/database_tasks.rb +++ b/activerecord/lib/active_record/tasks/database_tasks.rb @@ -69,11 +69,9 @@ 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 @@ -97,7 +95,6 @@ module ActiveRecord rescue Exception => error $stderr.puts error, *(error.backtrace) $stderr.puts "Couldn't drop #{configuration['database']}" - raise end def drop_all diff --git a/activerecord/test/cases/tasks/mysql_rake_test.rb b/activerecord/test/cases/tasks/mysql_rake_test.rb index 75adbb70e8..7bf902681e 100644 --- a/activerecord/test/cases/tasks/mysql_rake_test.rb +++ b/activerecord/test/cases/tasks/mysql_rake_test.rb @@ -62,9 +62,7 @@ module ActiveRecord ActiveRecord::StatementInvalid.new("Can't create database 'dev'; database exists:") ) - assert_raises(ActiveRecord::Tasks::DatabaseAlreadyExists) do - ActiveRecord::Tasks::DatabaseTasks.create @configuration - end + ActiveRecord::Tasks::DatabaseTasks.create @configuration end end diff --git a/activerecord/test/cases/tasks/postgresql_rake_test.rb b/activerecord/test/cases/tasks/postgresql_rake_test.rb index c01c6de593..43a474e59b 100644 --- a/activerecord/test/cases/tasks/postgresql_rake_test.rb +++ b/activerecord/test/cases/tasks/postgresql_rake_test.rb @@ -60,9 +60,7 @@ module ActiveRecord $stderr.expects(:puts). with("Couldn't create database for #{@configuration.inspect}") - assert_raises(Exception) do - ActiveRecord::Tasks::DatabaseTasks.create @configuration - end + ActiveRecord::Tasks::DatabaseTasks.create @configuration end def test_create_when_database_exists_outputs_info_to_stderr @@ -72,9 +70,7 @@ module ActiveRecord ActiveRecord::StatementInvalid.new('database "my-app-db" already exists') ) - assert_raises(ActiveRecord::Tasks::DatabaseAlreadyExists) do - ActiveRecord::Tasks::DatabaseTasks.create @configuration - end + ActiveRecord::Tasks::DatabaseTasks.create @configuration end end diff --git a/activerecord/test/cases/tasks/sqlite_rake_test.rb b/activerecord/test/cases/tasks/sqlite_rake_test.rb index 102bddf6a6..826855ef38 100644 --- a/activerecord/test/cases/tasks/sqlite_rake_test.rb +++ b/activerecord/test/cases/tasks/sqlite_rake_test.rb @@ -28,9 +28,7 @@ module ActiveRecord $stderr.expects(:puts).with("#{@database} already exists") - assert_raises(ActiveRecord::Tasks::DatabaseAlreadyExists) do - ActiveRecord::Tasks::DatabaseTasks.create @configuration, '/rails/root' - end + ActiveRecord::Tasks::DatabaseTasks.create @configuration, '/rails/root' end def test_db_create_with_file_does_nothing @@ -39,9 +37,7 @@ module ActiveRecord ActiveRecord::Base.expects(:establish_connection).never - assert_raises(ActiveRecord::Tasks::DatabaseAlreadyExists) do - ActiveRecord::Tasks::DatabaseTasks.create @configuration, '/rails/root' - end + ActiveRecord::Tasks::DatabaseTasks.create @configuration, '/rails/root' end def test_db_create_establishes_a_connection @@ -57,9 +53,7 @@ module ActiveRecord $stderr.expects(:puts). with("Couldn't create database for #{@configuration.inspect}") - assert_raises(Exception) do - ActiveRecord::Tasks::DatabaseTasks.create @configuration, '/rails/root' - end + ActiveRecord::Tasks::DatabaseTasks.create @configuration, '/rails/root' end end -- cgit v1.2.3