Skip to content

Commit

Permalink
Setup the new 3.0.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
beaud76 committed Mar 18, 2019
1 parent 924162a commit 0fe9217
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 18 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.0.0 (2019-Mar-19)
------
###Enhancements:###
* A psql script is supplied to install emaj on environments where it is not
possible to CREATE an EXTENSION (like PGaaS clouds).
Expand Down
8 changes: 4 additions & 4 deletions sql/emaj--2.3.1--devel.sql → sql/emaj--2.3.1--3.0.0.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--
-- E-Maj: migration from 2.3.1 to <devel>
-- E-Maj: migration from 2.3.1 to 3.0.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 2.3.1 started');
VALUES ('EMAJ_INSTALL','BEGIN','E-Maj 3.0.0', 'Upgrade from 2.3.1 started');

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

-- update the version id in the emaj_param table
UPDATE emaj.emaj_param SET param_value_text = '<devel>' WHERE param_key = 'emaj_version';
UPDATE emaj.emaj_param SET param_value_text = '3.0.0' 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 2.3.1 completed');
VALUES ('EMAJ_INSTALL','END','E-Maj 3.0.0', 'Upgrade from 2.3.1 completed');

-- post installation checks
DO
Expand Down
170 changes: 170 additions & 0 deletions sql/emaj--3.0.0--devel.sql
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;
1 change: 1 addition & 0 deletions tar.index
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ emaj-3.0.0/LICENSE
emaj-3.0.0/META.json
emaj-3.0.0/emaj.control
emaj-3.0.0/sql/emaj--3.0.0.sql
emaj-3.0.0/sql/emaj-3.0.0.sql
emaj-3.0.0/sql/emaj--2.3.1--3.0.0.sql
emaj-3.0.0/sql/emaj--2.3.0--2.3.1.sql
emaj-3.0.0/sql/emaj--2.2.3--2.3.0.sql
Expand Down
16 changes: 10 additions & 6 deletions tools/create_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,15 @@
echo "Adjusting $NEW content..."

# Delete tar files if exist
rm *.tar*
rm -f *.tar*

# Process doc directory: rename *devel* with *<new version>*
for file in doc/*devel*; do
mv $file $(echo $file | sed -r "s/devel/${NEW}/")
done
# Process doc directory: copy the Libre Office source documents from the emaj_doc directory, if any
cp ../emaj_doc/Emaj.devel_doc_en.odt doc/Emaj.${NEW}_doc_en.odt
cp ../emaj_doc/Emaj.devel_doc_fr.odt doc/Emaj.${NEW}_doc_fr.odt
cp ../emaj_doc/Emaj.devel_pres_en.odp doc/Emaj.${NEW}_pres_en.odp
cp ../emaj_doc/Emaj.devel_pres_fr.odp doc/Emaj.${NEW}_pres_fr.odp
cp ../emaj_doc/Emaj.devel_overview_en.odp doc/Emaj.${NEW}_overview_en.odp
cp ../emaj_doc/Emaj.devel_overview_fr.odp doc/Emaj.${NEW}_overview_fr.odp

# Process sql directory: change version identifiers inside the right files (excluding migration scripts)
for file in sql/*; do
Expand All @@ -79,7 +82,7 @@
fi
done
git mv sql/emaj--devel.sql sql/emaj--${NEW}.sql
git mv sql/emaj--devel.psql sql/emaj--${NEW}.psql
git mv sql/emaj-devel.sql sql/emaj-${NEW}.sql

# Change version identifiers inside files from /client + + META.json README.md
find client META.json README.md -type f -exec sed -i "s/<devel>/${NEW}/g" '{}' \;
Expand All @@ -92,6 +95,7 @@

# Change version identifiers inside files from /test/sql
find test/sql -type f -exec sed -i "s/'devel'/'${NEW}'/g" '{}' \;
sed -i "s/emaj-devel.sql/emaj-${NEW}.sql/" test/sql/install_psql.sql

# Change environment directories and files into tools
sed -i "s/\/emaj/\/emaj-${NEW}/" tools/copy2Expected.sh
Expand Down
19 changes: 11 additions & 8 deletions tools/emaj_upgrade.template
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ $do$
IF v_emajVersion <> '<PREVIOUS_VERSION>' THEN
RAISE EXCEPTION 'E-Maj upgrade: the current E-Maj version (%) is not <PREVIOUS_VERSION>',v_emajVersion;
END IF;
-- the installed postgres version must be at least 9.2
IF current_setting('server_version_num')::int < 90200 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.2.', current_setting('server_version');
-- 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
Expand Down Expand Up @@ -122,13 +127,11 @@ $tmp$
DECLARE
v_event_trigger_array TEXT[];
BEGIN
IF emaj._pg_version_num() >= 90300 THEN
-- 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';
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 IF;
PERFORM emaj._enable_event_triggers(v_event_trigger_array);
END;
$tmp$;

Expand Down

0 comments on commit 0fe9217

Please sign in to comment.