Skip to content

Instantly share code, notes, and snippets.

@ak47
Created July 28, 2011 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ak47/1112071 to your computer and use it in GitHub Desktop.
Save ak47/1112071 to your computer and use it in GitHub Desktop.
alter activerecord-3.0.9/lib/active_record/railties/databases.rake
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'
puts config
ActiveRecord::Base.connection.select_all("select * from pg_stat_activity order by procpid;").each do |x|
puts x
if config['database'] == x['datname'] && x['current_query'] == '<IDLE>'
ActiveRecord::Base.connection.execute("select pg_terminate_backend(#{x['procpid']})")
end
end
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
ActiveRecord::Base.connection.drop_database config['database']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment