6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/pgreset.rb', line 6
def drop
if respond_to?(:configuration_hash, true)
database_name = configuration_hash.with_indifferent_access.fetch(:database)
establish_connection(configuration_hash.merge(database: "postgres", schema_search_path: "public"))
else
database_name = configuration['database']
establish_connection(configuration.merge(database: "postgres", schema_search_path: "public"))
end
pid_column = 'pid' if 0 == connection.select_all("SELECT column_name FROM information_schema.columns WHERE table_name = 'pg_stat_activity' AND column_name = 'pid';").count
pid_column = 'procpid' end
connection.select_all "SELECT pg_terminate_backend(pg_stat_activity.#{pid_column}) FROM pg_stat_activity WHERE datname='#{database_name}' AND #{pid_column} <> pg_backend_pid();"
connection.drop_database database_name
end
|