Skip to content

Commit

Permalink
optimized rake:db:drop and instead of dropping the connections to the…
Browse files Browse the repository at this point in the history
… db after forking, we are not clearing the connection cached allowing rake tasks to run properly.
  • Loading branch information
mattetti committed Jan 27, 2009
1 parent 30b1c02 commit 0aaecd3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion merb_activerecord/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GEM_EMAIL = "[email protected]"

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}"

Expand Down
23 changes: 15 additions & 8 deletions merb_activerecord/lib/active_record/merbtasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions merb_activerecord/lib/merb_activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0aaecd3

Please sign in to comment.