Created
March 26, 2016 22:50
-
-
Save AlexVKO/21f1b45e19da1fff6fc6 to your computer and use it in GitHub Desktop.
rake drop database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record/connection_adapters/postgresql_adapter' | |
module ActiveRecord | |
module ConnectionAdapters | |
class PostgreSQLAdapter < AbstractAdapter | |
def drop_database(name) | |
raise "Nah, I won't drop the production database" if Rails.env.production? | |
execute <<-SQL | |
UPDATE pg_catalog.pg_database | |
SET datallowconn=false WHERE datname='#{name}' | |
SQL | |
execute <<-SQL | |
SELECT pg_terminate_backend(pg_stat_activity.pid) | |
FROM pg_stat_activity | |
WHERE pg_stat_activity.datname = '#{name}'; | |
SQL | |
execute "DROP DATABASE IF EXISTS #{quote_table_name(name)}" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment