From 0a0d752d42514082ff5aad5c2932c209f1cd4b42 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Tue, 20 Apr 2010 13:50:26 -0400 Subject: [PATCH] [PATCH] db:drop:all throws error when database does not exist [#2997 state:resolved] --- railties/lib/tasks/databases.rake | 28 ++++++++++++++-------------- 1 files changed, 14 insertions(+), 14 deletions(-) diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 8b60839..0c83311 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -94,11 +94,7 @@ namespace :db do desc 'Drops the database for the current RAILS_ENV' task :drop => :load_config do config = ActiveRecord::Base.configurations[RAILS_ENV || 'development'] - begin - drop_database(config) - rescue Exception => e - puts "Couldn't drop #{config['database']} : #{e.inspect}" - end + drop_database(config) end def local_database?(config, &block) @@ -410,15 +406,19 @@ namespace :db do end def drop_database(config) - case config['adapter'] - when 'mysql' - ActiveRecord::Base.establish_connection(config) - ActiveRecord::Base.connection.drop_database config['database'] - when /^sqlite/ - FileUtils.rm(File.join(RAILS_ROOT, config['database'])) - when 'postgresql' - ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public')) - ActiveRecord::Base.connection.drop_database config['database'] + begin + case config['adapter'] + when 'mysql' + ActiveRecord::Base.establish_connection(config) + ActiveRecord::Base.connection.drop_database config['database'] + when /^sqlite/ + FileUtils.rm(File.join(RAILS_ROOT, config['database'])) + when 'postgresql' + ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public')) + ActiveRecord::Base.connection.drop_database config['database'] + end + rescue Exception => e + puts "Couldn't drop #{config['database']} : #{e.inspect}" end end -- 1.6.5.2