Skip to content
This repository
Browse code

db:drop:all throws error when database does not exist [#2997 state:re…

…solved]

Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
  • Loading branch information...
commit 22b020db3ed3992b510b91d3fd423e510b9369e4 1 parent 2de3646
Neeraj Singh authored jeremy committed

Showing 1 changed file with 14 additions and 14 deletions. Show diff stats Hide diff stats

  1. 28  railties/lib/tasks/databases.rake
28  railties/lib/tasks/databases.rake
@@ -94,11 +94,7 @@ namespace :db do
94 94
   desc 'Drops the database for the current RAILS_ENV'
95 95
   task :drop => :load_config do
96 96
     config = ActiveRecord::Base.configurations[RAILS_ENV || 'development']
97  
-    begin
98  
-      drop_database(config)
99  
-    rescue Exception => e
100  
-      puts "Couldn't drop #{config['database']} : #{e.inspect}"
101  
-    end
  97
+    drop_database(config)
102 98
   end
103 99
 
104 100
   def local_database?(config, &block)
@@ -410,15 +406,19 @@ namespace :db do
410 406
 end
411 407
 
412 408
 def drop_database(config)
413  
-  case config['adapter']
414  
-  when 'mysql'
415  
-    ActiveRecord::Base.establish_connection(config)
416  
-    ActiveRecord::Base.connection.drop_database config['database']
417  
-  when /^sqlite/
418  
-    FileUtils.rm(File.join(RAILS_ROOT, config['database']))
419  
-  when 'postgresql'
420  
-    ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
421  
-    ActiveRecord::Base.connection.drop_database config['database']
  409
+  begin
  410
+    case config['adapter']
  411
+    when 'mysql'
  412
+      ActiveRecord::Base.establish_connection(config)
  413
+      ActiveRecord::Base.connection.drop_database config['database']
  414
+    when /^sqlite/
  415
+      FileUtils.rm(File.join(RAILS_ROOT, config['database']))
  416
+    when 'postgresql'
  417
+      ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
  418
+      ActiveRecord::Base.connection.drop_database config['database']
  419
+    end
  420
+  rescue Exception => e
  421
+    puts "Couldn't drop #{config['database']} : #{e.inspect}"
422 422
   end
423 423
 end
424 424
 

0 notes on commit 22b020d

Please sign in to comment.
Something went wrong with that request. Please try again.