1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/config/initializers/postgresql_database_tasks.rb

18 lines
584 B
Ruby
Raw Normal View History

2021-02-24 11:03:36 +01:00
# frozen_string_literal: true
2023-02-24 17:26:55 +01:00
# The following magic allows to drop a PG database even if a connection exists
# @see https://stackoverflow.com/a/38710021
class ActiveRecord::Tasks::PostgreSQLDatabaseTasks
include ActiveRecord::Sanitization::ClassMethods
2021-02-24 11:03:36 +01:00
2023-02-24 17:26:55 +01:00
def drop
establish_master_connection
q = sanitize_sql_array [
"select pg_terminate_backend(pg_stat_activity.pid) from pg_stat_activity where datname= ? AND state='idle';",
configuration_hash[:database]
]
connection.select_all q
connection.drop_database configuration_hash[:database]
2016-03-23 18:39:41 +01:00
end
2021-02-24 11:03:36 +01:00
end