Permalink
Browse files

optimized rake:db:drop and instead of dropping the connections to the…

… db after forking, we are not clearing the connection cached allowing rake tasks to run properly.
  • Loading branch information...
1 parent 30b1c02 commit 0aaecd306a1561e288d7a9b9a3a974eefcc5eb00 @mattetti mattetti committed Jan 27, 2009
@@ -17,7 +17,7 @@ GEM_EMAIL = "canadaduane@gmail.com"
GEM_NAME = "merb_activerecord"
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
-GEM_VERSION = ("1.0.0") + PKG_BUILD
+GEM_VERSION = ("1.0.0.1") + PKG_BUILD
RELEASE_NAME = "REL #{GEM_VERSION}"
@@ -53,14 +53,21 @@ def create_local_database(config)
end
def drop_database(config)
- case config[:adapter]
- when 'mysql'
- ActiveRecord::Base.connection.drop_database config[:database]
- when /^sqlite/
- FileUtils.rm(File.join(Merb.root, config[:database]))
- when 'postgresql'
- ActiveRecord::Base.clear_active_connections!
- `dropdb "#{config[:database]}"`
+ begin
+ ActiveRecord::Base.establish_connection(config)
+ ActiveRecord::Base.connection
+ rescue
+ puts "could not connect to #{config[:database]}, database not dropped"
+ else
+ case config[:adapter]
+ when 'mysql'
+ ActiveRecord::Base.connection.drop_database config[:database]
+ when /^sqlite/
+ FileUtils.rm(File.join(Merb.root, config[:database]))
+ when 'postgresql'
+ ActiveRecord::Base.clear_active_connections!
+ `dropdb "#{config[:database]}"`
+ end
end
end
@@ -27,10 +27,10 @@ class Merb::Orms::ActiveRecord::DisconnectBeforeFork < Merb::BootLoader
def self.run
Merb.logger.debug "Disconnecting database connection before forking."
- ::ActiveRecord::Base.connection.disconnect!
+ ::ActiveRecord::Base.clear_active_connections!
end
-
- end
+ end
+
generators = File.join(File.dirname(__FILE__), 'generators')
Merb.add_generators generators / :migration

0 comments on commit 0aaecd3

Please sign in to comment.