Skip to content

Commit

Permalink
Setup the new 3.3.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
beaud76 committed Mar 14, 2020
1 parent 89e8e67 commit efdee31
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ E-Maj - Change log
==================
<devel>
------
###Enhancements:###


###Bug fixes:###



3.3.0 (2020-Mar-14)
------
###Enhancements:###
* Two new emaj_export_groups_configuration() functions allow to export
tables groups configurations as a JSON structure, either directly or into
Expand Down
8 changes: 4 additions & 4 deletions sql/emaj--3.2.0--devel.sql → sql/emaj--3.2.0--3.3.0.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--
-- E-Maj: migration from 3.2.0 to <devel>
-- E-Maj: migration from 3.2.0 to 3.3.0
--
-- This software is distributed under the GNU General Public License.
--
Expand Down Expand Up @@ -57,7 +57,7 @@ $do$;

-- 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.2.0 started');
VALUES ('EMAJ_INSTALL','BEGIN','E-Maj 3.3.0', 'Upgrade from 3.2.0 started');

-- lock emaj_group table to avoid any concurrent E-Maj activity
LOCK TABLE emaj.emaj_group IN EXCLUSIVE MODE;
Expand Down Expand Up @@ -5120,12 +5120,12 @@ INSERT INTO pg_catalog.pg_description (objoid, classoid, objsubid, description)

-- update the version id in the emaj_param table
ALTER TABLE emaj.emaj_param DISABLE TRIGGER emaj_param_change_trg;
UPDATE emaj.emaj_param SET param_value_text = '<devel>' WHERE param_key = 'emaj_version';
UPDATE emaj.emaj_param SET param_value_text = '3.3.0' WHERE param_key = 'emaj_version';
ALTER TABLE emaj.emaj_param ENABLE TRIGGER emaj_param_change_trg;

-- 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.2.0 completed');
VALUES ('EMAJ_INSTALL','END','E-Maj 3.3.0', 'Upgrade from 3.2.0 completed');

-- post installation checks
DO
Expand Down
175 changes: 175 additions & 0 deletions sql/emaj--3.3.0--devel.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
--
-- E-Maj: migration from 3.3.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.3.0'
SELECT param_value_text INTO v_emajVersion FROM emaj.emaj_param WHERE param_key = 'emaj_version';
IF v_emajVersion <> '3.3.0' THEN
RAISE EXCEPTION 'E-Maj upgrade: the current E-Maj version (%) is not 3.3.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;
-- the E-Maj environment is not damaged
PERFORM * FROM (SELECT * FROM emaj.emaj_verify_all()) AS t(msg) WHERE msg <> 'No error detected';
IF FOUND THEN
RAISE EXCEPTION 'E-Maj upgrade: the E-Maj environment is damaged. Please fix the issue before upgrading. You may execute "SELECT * FROM emaj.emaj_verify_all();" to get more details.';
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.3.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.3.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;

0 comments on commit efdee31

Please sign in to comment.