From dee68ef36c7f9cef79a9c714f084c96e68fd7325 Mon Sep 17 00:00:00 2001 From: pivotal Date: Mon, 24 Aug 2009 17:16:58 -0700 Subject: [PATCH] DRY'ed drop_database(config) --- railties/lib/tasks/databases.rake | 43 ++++++++++++++++-------------------- 1 files changed, 19 insertions(+), 24 deletions(-) diff --git a/railties/lib/tasks/databases.rake b/railties/lib/tasks/databases.rake index 687bc00..542b751 100644 --- a/railties/lib/tasks/databases.rake +++ b/railties/lib/tasks/databases.rake @@ -101,12 +101,7 @@ namespace :db do ActiveRecord::Base.configurations.each_value do |config| # Skip entries that don't have a database key next unless config['database'] - begin - # Only connect to local databases - local_database?(config) { drop_database(config) } - rescue Exception => e - puts "Couldn't drop #{config['database']} : #{e.inspect}" - end + local_database?(config) { drop_database(config) } end end end @@ -114,11 +109,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) @@ -439,19 +430,23 @@ 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/ - require 'pathname' - path = Pathname.new(config['database']) - file = path.absolute? ? path.to_s : File.join(RAILS_ROOT, path) - - FileUtils.rm(file) - 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/ + require 'pathname' + path = Pathname.new(config['database']) + file = path.absolute? ? path.to_s : File.join(RAILS_ROOT, path) + + FileUtils.rm(file) + 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.0.1