forked from pgMemento/pgMemento
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UNINSTALL_PGMEMENTO.sql
53 lines (47 loc) · 1.57 KB
/
UNINSTALL_PGMEMENTO.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- UNINSTALL_PGMEMENTO.sql
--
-- Author: Felix Kunde <[email protected]>
--
-- This script is free software under the LGPL Version 3
-- See the GNU Lesser General Public License at
-- http://www.gnu.org/copyleft/lgpl.html
-- for more details.
-------------------------------------------------------------------------------
-- About:
-- Script to remove pgMemento from a database
-------------------------------------------------------------------------------
--
-- ChangeLog:
--
-- Version | Date | Description | Author
-- 0.4.0 2020-04-13 reflect configurable audit_id column FKun
-- 0.3.0 2020-03-23 use audit_tables view to delete pgMemento FKun
-- 0.2.0 2017-07-26 reflect changes of later pgMemento versions FKun
-- 0.1.0 2015-06-20 initial commit FKun
--
\pset footer off
SET client_min_messages TO WARNING;
\set ON_ERROR_STOP ON
\echo
\echo 'Removing event triggers ...'
SELECT pgmemento.drop_schema_event_trigger();
\echo
\echo 'Removing audit_id columns from audited tables ...'
SELECT
pgmemento.drop_table_audit(
tablename,
schemaname,
audit_id_column,
FALSE
)
FROM
pgmemento.audit_tables;
\echo
\echo 'Removing pgmemento schema ...'
DROP SCHEMA pgmemento CASCADE;
\echo
\echo 'Updating search path ...'
SELECT replace(current_setting('search_path'), ', pgmemento', '') AS db_path \gset
ALTER DATABASE :"DBNAME" SET search_path TO :db_path;
\echo
\echo 'pgMemento completely removed!'