-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
205 additions
and
18 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
-- | ||
-- E-Maj: migration from 3.0.0 to <devel> | ||
-- | ||
-- This software is distributed under the GNU General Public License. | ||
-- | ||
-- This script upgrades an existing installation of E-Maj extension. | ||
-- | ||
|
||
-- complain if this script is executed in psql, rather than via an ALTER EXTENSION statement | ||
\echo Use "ALTER EXTENSION emaj UPDATE TO..." to upgrade the E-Maj extension. \quit | ||
|
||
--SET client_min_messages TO WARNING; | ||
SET client_min_messages TO NOTICE; | ||
|
||
------------------------------------ | ||
-- -- | ||
-- checks -- | ||
-- -- | ||
------------------------------------ | ||
-- Check that the upgrade conditions are met. | ||
DO | ||
$do$ | ||
DECLARE | ||
v_emajVersion TEXT; | ||
v_groupList TEXT; | ||
BEGIN | ||
-- check the current role is a superuser | ||
PERFORM 0 FROM pg_roles WHERE rolname = current_user AND rolsuper; | ||
IF NOT FOUND THEN | ||
RAISE EXCEPTION 'E-Maj upgrade: the current user (%) is not a superuser.', current_user; | ||
END IF; | ||
-- the emaj version registered in emaj_param must be '3.0.0' | ||
SELECT param_value_text INTO v_emajVersion FROM emaj.emaj_param WHERE param_key = 'emaj_version'; | ||
IF v_emajVersion <> '3.0.0' THEN | ||
RAISE EXCEPTION 'E-Maj upgrade: the current E-Maj version (%) is not 3.0.0',v_emajVersion; | ||
END IF; | ||
-- the installed postgres version must be at least 9.5 | ||
IF current_setting('server_version_num')::int < 90500 THEN | ||
RAISE EXCEPTION 'E-Maj upgrade: the current PostgreSQL version (%) is not compatible with the new E-Maj version. The PostgreSQL version should be at least 9.5.', current_setting('server_version'); | ||
END IF; | ||
-- no existing group must have been created with a postgres version prior 8.4 | ||
SELECT string_agg(group_name, ', ') INTO v_groupList FROM emaj.emaj_group | ||
WHERE cast(to_number(substring(group_pg_version FROM E'^(\\d+)'),'99') * 100 + | ||
to_number(substring(group_pg_version FROM E'^\\d+\\.(\\d+)'),'99') AS INTEGER) < 804; | ||
IF v_groupList IS NOT NULL THEN | ||
RAISE EXCEPTION 'E-Maj upgrade: groups "%" have been created with a too old postgres version (< 8.4). Drop these groups before upgrading. ',v_groupList; | ||
END IF; | ||
END; | ||
$do$; | ||
|
||
-- OK, the upgrade operation can start... | ||
|
||
-- insert the upgrade begin record in the operation history | ||
INSERT INTO emaj.emaj_hist (hist_function, hist_event, hist_object, hist_wording) | ||
VALUES ('EMAJ_INSTALL','BEGIN','E-Maj <devel>', 'Upgrade from 3.0.0 started'); | ||
|
||
-- lock emaj_group table to avoid any concurrent E-Maj activity | ||
LOCK TABLE emaj.emaj_group IN EXCLUSIVE MODE; | ||
|
||
-- disable the event triggers | ||
SELECT emaj._disable_event_triggers(); | ||
|
||
---------------------------------------------- | ||
-- -- | ||
-- emaj enums, tables, views and sequences -- | ||
-- -- | ||
---------------------------------------------- | ||
|
||
|
||
-- | ||
-- add created or recreated tables and sequences to the list of content to save by pg_dump | ||
-- | ||
|
||
------------------------------------ | ||
-- -- | ||
-- emaj types -- | ||
-- -- | ||
------------------------------------ | ||
|
||
------------------------------------ | ||
-- -- | ||
-- emaj functions -- | ||
-- -- | ||
------------------------------------ | ||
-- recreate functions that have been previously dropped in the tables structure upgrade step and will not be recreated later in this script | ||
|
||
|
||
--<begin_functions> pattern used by the tool that extracts and insert the functions definition | ||
|
||
--<end_functions> pattern used by the tool that extracts and insert the functions definition | ||
------------------------------------------ | ||
-- -- | ||
-- event triggers and related functions -- | ||
-- -- | ||
------------------------------------------ | ||
|
||
------------------------------------ | ||
-- -- | ||
-- emaj roles and rights -- | ||
-- -- | ||
------------------------------------ | ||
REVOKE ALL ON ALL FUNCTIONS IN SCHEMA emaj FROM PUBLIC; | ||
|
||
GRANT ALL ON ALL TABLES IN SCHEMA emaj TO emaj_adm; | ||
GRANT ALL ON ALL SEQUENCES IN SCHEMA emaj TO emaj_adm; | ||
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA emaj TO emaj_adm; | ||
|
||
GRANT SELECT ON ALL TABLES IN SCHEMA emaj TO emaj_viewer; | ||
GRANT SELECT ON ALL SEQUENCES IN SCHEMA emaj TO emaj_viewer; | ||
REVOKE SELECT ON TABLE emaj.emaj_param FROM emaj_viewer; | ||
|
||
|
||
------------------------------------ | ||
-- -- | ||
-- complete the upgrade -- | ||
-- -- | ||
------------------------------------ | ||
|
||
-- enable the event triggers | ||
DO | ||
$tmp$ | ||
DECLARE | ||
v_event_trigger_array TEXT[]; | ||
BEGIN | ||
-- build the event trigger names array from the pg_event_trigger table | ||
SELECT coalesce(array_agg(evtname),ARRAY[]::TEXT[]) INTO v_event_trigger_array | ||
FROM pg_catalog.pg_event_trigger WHERE evtname LIKE 'emaj%' AND evtenabled = 'D'; | ||
-- call the _enable_event_triggers() function | ||
PERFORM emaj._enable_event_triggers(v_event_trigger_array); | ||
END; | ||
$tmp$; | ||
|
||
-- Set comments for all internal functions, | ||
-- by directly inserting a row in the pg_description table for all emaj functions that do not have yet a recorded comment | ||
INSERT INTO pg_catalog.pg_description (objoid, classoid, objsubid, description) | ||
SELECT pg_proc.oid, pg_class.oid, 0 , 'E-Maj internal function' | ||
FROM pg_catalog.pg_proc, pg_catalog.pg_class | ||
WHERE pg_class.relname = 'pg_proc' | ||
AND pg_proc.oid IN -- list all emaj functions that do not have yet a comment in pg_description | ||
(SELECT pg_proc.oid | ||
FROM pg_catalog.pg_proc | ||
JOIN pg_catalog.pg_namespace ON (pronamespace=pg_namespace.oid) | ||
LEFT OUTER JOIN pg_catalog.pg_description ON (pg_description.objoid = pg_proc.oid | ||
AND classoid = (SELECT oid FROM pg_catalog.pg_class WHERE relname = 'pg_proc') | ||
AND objsubid = 0) | ||
WHERE nspname = 'emaj' AND (proname LIKE E'emaj\\_%' OR proname LIKE E'\\_%') | ||
AND pg_description.description IS NULL | ||
); | ||
|
||
-- update the version id in the emaj_param table | ||
UPDATE emaj.emaj_param SET param_value_text = '<devel>' WHERE param_key = 'emaj_version'; | ||
|
||
-- insert the upgrade end record in the operation history | ||
INSERT INTO emaj.emaj_hist (hist_function, hist_event, hist_object, hist_wording) | ||
VALUES ('EMAJ_INSTALL','END','E-Maj <devel>', 'Upgrade from 3.0.0 completed'); | ||
|
||
-- post installation checks | ||
DO | ||
$tmp$ | ||
DECLARE | ||
BEGIN | ||
-- check the max_prepared_transactions GUC value | ||
IF current_setting('max_prepared_transactions')::int <= 1 THEN | ||
RAISE WARNING 'E-Maj upgrade: as the max_prepared_transactions parameter value (%) on this cluster is too low, no parallel rollback is possible.', current_setting('max_prepared_transactions'); | ||
END IF; | ||
END; | ||
$tmp$; | ||
|
||
RESET default_tablespace; | ||
SET client_min_messages TO default; |
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
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
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