Skip to content

Commit

Permalink
In tables groups configuration import and export functions, symplify …
Browse files Browse the repository at this point in the history
…the JSON formatting for the "ignored_triggers" property, by using a simple string array. This breaks the compatibility with json configurations produced by the emaj_export_groups_configuration() function executed in previous E-Maj versions. But the feature is quite new and it is worth doing it now with the coming 4.0 version that already changes the API on other aspects.
  • Loading branch information
beaud76 committed Oct 25, 2020
1 parent c22c75a commit 88958d8
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 410 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ E-Maj - Change log
the emaj_assign_table(), emaj_assign_tables(), emaj_modify_table() or
emaj_modify_tables()functions. This replaces the now dropped
emaj_ignore_app_trigger() function.
* In tables groups configuration import and export functions, symplify the
JSON formatting for the "ignored_triggers" property, by using a simple
string array.
* Remove the old deprecated versions of E-Maj rollback functions that only
returned an integer.
* A fourth parameter in the emaj_import_groups_configuration() functions
Expand Down
27 changes: 11 additions & 16 deletions docs/en/otherGroupsFunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,31 +196,26 @@ If the file path is not supplied (i.e. is set to NULL), the function directly re
"_comment": "Generated on database <db> with E-Maj version <version> at <date_heure>",
"tables_groups": [
{
"group": "...",
"is_rollbackable": ...,
"comment": "...",
"group": "ggg",
"is_rollbackable": true|false,
"comment": "ccc",
"tables": [
{
"schema": "...",
"table": "...",
"priority": ...,
"log_data_tablespace": "...",
"log_index_tablespace": "...",
"ignored_triggers": [
{
"trigger": "...",
...
},
]
"schema": "sss",
"table": "ttt",
"priority": ppp,
"log_data_tablespace": "lll",
"log_index_tablespace": "lll",
"ignored_triggers": [ "tg1", "tg2", ... ]
},
{
...
}
],
"sequences": [
{
"schema": "myschema1",
"sequence": "mytbl1",
"schema": "sss",
"sequence": "sss",
},
{
...
Expand Down
27 changes: 11 additions & 16 deletions docs/fr/otherGroupsFunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -195,31 +195,26 @@ Si le chemin du fichier n’est pas renseigné (i.e. est valorisé à NULL), la
"_comment": "Generated on database <db> with E-Maj version <version> at <date_heure>",
"tables_groups": [
{
"group": "...",
"is_rollbackable": ...,
"comment": "...",
"group": "ggg",
"is_rollbackable": true|false,
"comment": "ccc",
"tables": [
{
"schema": "...",
"table": "...",
"priority": ...,
"log_data_tablespace": "...",
"log_index_tablespace": "...",
"ignored_triggers": [
{
"trigger": "...",
...
},
]
"schema": "sss",
"table": "ttt",
"priority": ppp,
"log_data_tablespace": "lll",
"log_index_tablespace": "lll",
"ignored_triggers": [ "tg1", "tg2", ... ]
},
{
...
}
],
"sequences": [
{
"schema": "myschema1",
"sequence": "mytbl1",
"schema": "sss",
"sequence": "sss",
},
{
...
Expand Down
81 changes: 27 additions & 54 deletions sql/emaj--3.4.0--devel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -591,32 +591,29 @@ $_check_json_groups_conf$
v_group, quote_ident(v_schema), quote_ident(v_tblseq)));
END IF;
-- process triggers attributes
v_triggerNumber = 0;
FOR r_trigger IN
SELECT value AS triggerJson
FROM json_array_elements(r_table.tableJson -> 'ignored_triggers')
LOOP
v_triggerNumber = v_triggerNumber + 1;
v_trigger = r_trigger.triggerJson ->> 'trigger';
-- the "trigger" attribute must exists
IF v_trigger IS NULL OR v_trigger = '' THEN
RETURN QUERY
VALUES (224, 1, v_group, v_schema, v_tblseq, NULL::TEXT, v_triggerNumber,
format('In the tables group "%s" and for the table %I.%I, the trigger #%s has no "trigger" attribute.',
v_group, quote_ident(v_schema), quote_ident(v_tblseq), v_triggerNumber));
IF r_table.tableJson -> 'ignored_triggers' IS NOT NULL THEN
IF json_typeof(r_table.tableJson -> 'ignored_triggers') = 'array' THEN
v_triggerNumber = 0;
FOR r_trigger IN
SELECT value AS triggerJson
FROM json_array_elements(r_table.tableJson -> 'ignored_triggers')
LOOP
v_triggerNumber = v_triggerNumber + 1;
IF json_typeof(r_trigger.triggerJson) <> 'string' THEN
RETURN QUERY
VALUES (226, 1, v_group, v_schema, v_tblseq, NULL::TEXT, v_triggerNumber,
format('In the tables group "%s" and for the table %I.%I, the trigger #%s is not a string. '
'This is required since E-Maj 4.0.',
v_group, quote_ident(v_schema), quote_ident(v_tblseq), v_triggerNumber));
END IF;
END LOOP;
ELSE
-- attributes of the ignored_triggers level must exist
RETURN QUERY
SELECT 225, 1, v_group, v_schema, v_tblseq, key, NULL::INT,
format('In the tables group "%s" and for a trigger of the table %I.%I, the keyword "%s" is unknown.',
v_group, quote_ident(v_schema), quote_ident(v_tblseq), key)
FROM (
SELECT key
FROM json_object_keys(r_trigger.triggerJson) AS x(key)
WHERE key NOT IN ('trigger')
) AS t;
VALUES (227, 1, v_group, v_schema, v_tblseq, NULL::TEXT, NULL::INT,
format('In the tables group "%s" and for the table %I.%I, the "ignored_triggers" attribute is not an array.',
v_group, quote_ident(v_schema), quote_ident(v_tblseq)));
END IF;
END LOOP;
END IF;
END IF;
END LOOP;
-- process sequences attributes
Expand Down Expand Up @@ -5229,7 +5226,6 @@ $_export_groups_conf$
v_groupsText TEXT;
v_unknownGroupsList TEXT;
v_groupsJson JSON;
v_trg_name TEXT;
r_group RECORD;
r_table RECORD;
r_sequence RECORD;
Expand Down Expand Up @@ -5286,34 +5282,11 @@ $_export_groups_conf$
v_groupsText = v_groupsText
|| E' {\n'
|| ' "schema": ' || to_json(r_table.rel_schema) || E',\n'
|| ' "table": ' || to_json(r_table.rel_tblseq) || E',\n';
IF r_table.rel_priority IS NOT NULL THEN
v_groupsText = v_groupsText
|| E' "priority": '|| to_json(r_table.rel_priority) || E',\n';
END IF;
IF r_table.rel_log_dat_tsp IS NOT NULL THEN
v_groupsText = v_groupsText
|| E' "log_data_tablespace": '|| to_json(r_table.rel_log_dat_tsp) || E',\n';
END IF;
IF r_table.rel_log_idx_tsp IS NOT NULL THEN
v_groupsText = v_groupsText
|| E' "log_index_tablespace": '|| to_json(r_table.rel_log_idx_tsp) || E',\n';
END IF;
IF r_table.rel_ignored_triggers IS NOT NULL THEN
-- build the triggers to ignore for the table, if any
v_groupsText = v_groupsText
|| E' "ignored_triggers": [\n';
FOREACH v_trg_name IN ARRAY r_table.rel_ignored_triggers
LOOP
v_groupsText = v_groupsText
|| E' {\n'
|| ' "trigger": ' || to_json(v_trg_name) || E',\n'
|| E' },\n';
END LOOP;
v_groupsText = v_groupsText
|| E' ],\n';
END IF;
v_groupsText = v_groupsText
|| ' "table": ' || to_json(r_table.rel_tblseq) || E',\n'
|| coalesce(' "priority": '|| to_json(r_table.rel_priority) || E',\n', '')
|| coalesce(' "log_data_tablespace": '|| to_json(r_table.rel_log_dat_tsp) || E',\n', '')
|| coalesce(' "log_index_tablespace": '|| to_json(r_table.rel_log_idx_tsp) || E',\n', '')
|| coalesce(' "ignored_triggers": ' || array_to_json(r_table.rel_ignored_triggers) || E',\n', '')
|| E' },\n';
END LOOP;
v_groupsText = v_groupsText
Expand Down Expand Up @@ -5620,8 +5593,8 @@ $_import_groups_conf_prepare$
FROM json_array_elements(r_group.groupJson -> 'tables')
LOOP
-- prepare the array of trigger names for the table
SELECT array_agg("trigger" ORDER BY "trigger") INTO v_ignoredTriggers
FROM json_to_recordset(r_table.tableJson -> 'ignored_triggers') AS x("trigger" TEXT);
SELECT array_agg("value" ORDER BY "value") INTO v_ignoredTriggers
FROM json_array_elements_text(r_table.tableJson -> 'ignored_triggers') AS t;
-- ... and insert
INSERT INTO tmp_app_table(tmp_group, tmp_schema, tmp_tbl_name,
tmp_priority, tmp_log_dat_tsp, tmp_log_idx_tsp, tmp_ignored_triggers)
Expand Down
81 changes: 27 additions & 54 deletions sql/emaj--devel.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1095,32 +1095,29 @@ $_check_json_groups_conf$
v_group, quote_ident(v_schema), quote_ident(v_tblseq)));
END IF;
-- process triggers attributes
v_triggerNumber = 0;
FOR r_trigger IN
SELECT value AS triggerJson
FROM json_array_elements(r_table.tableJson -> 'ignored_triggers')
LOOP
v_triggerNumber = v_triggerNumber + 1;
v_trigger = r_trigger.triggerJson ->> 'trigger';
-- the "trigger" attribute must exists
IF v_trigger IS NULL OR v_trigger = '' THEN
RETURN QUERY
VALUES (224, 1, v_group, v_schema, v_tblseq, NULL::TEXT, v_triggerNumber,
format('In the tables group "%s" and for the table %I.%I, the trigger #%s has no "trigger" attribute.',
v_group, quote_ident(v_schema), quote_ident(v_tblseq), v_triggerNumber));
IF r_table.tableJson -> 'ignored_triggers' IS NOT NULL THEN
IF json_typeof(r_table.tableJson -> 'ignored_triggers') = 'array' THEN
v_triggerNumber = 0;
FOR r_trigger IN
SELECT value AS triggerJson
FROM json_array_elements(r_table.tableJson -> 'ignored_triggers')
LOOP
v_triggerNumber = v_triggerNumber + 1;
IF json_typeof(r_trigger.triggerJson) <> 'string' THEN
RETURN QUERY
VALUES (226, 1, v_group, v_schema, v_tblseq, NULL::TEXT, v_triggerNumber,
format('In the tables group "%s" and for the table %I.%I, the trigger #%s is not a string. '
'This is required since E-Maj 4.0.',
v_group, quote_ident(v_schema), quote_ident(v_tblseq), v_triggerNumber));
END IF;
END LOOP;
ELSE
-- attributes of the ignored_triggers level must exist
RETURN QUERY
SELECT 225, 1, v_group, v_schema, v_tblseq, key, NULL::INT,
format('In the tables group "%s" and for a trigger of the table %I.%I, the keyword "%s" is unknown.',
v_group, quote_ident(v_schema), quote_ident(v_tblseq), key)
FROM (
SELECT key
FROM json_object_keys(r_trigger.triggerJson) AS x(key)
WHERE key NOT IN ('trigger')
) AS t;
VALUES (227, 1, v_group, v_schema, v_tblseq, NULL::TEXT, NULL::INT,
format('In the tables group "%s" and for the table %I.%I, the "ignored_triggers" attribute is not an array.',
v_group, quote_ident(v_schema), quote_ident(v_tblseq)));
END IF;
END LOOP;
END IF;
END IF;
END LOOP;
-- process sequences attributes
Expand Down Expand Up @@ -6132,7 +6129,6 @@ $_export_groups_conf$
v_groupsText TEXT;
v_unknownGroupsList TEXT;
v_groupsJson JSON;
v_trg_name TEXT;
r_group RECORD;
r_table RECORD;
r_sequence RECORD;
Expand Down Expand Up @@ -6189,34 +6185,11 @@ $_export_groups_conf$
v_groupsText = v_groupsText
|| E' {\n'
|| ' "schema": ' || to_json(r_table.rel_schema) || E',\n'
|| ' "table": ' || to_json(r_table.rel_tblseq) || E',\n';
IF r_table.rel_priority IS NOT NULL THEN
v_groupsText = v_groupsText
|| E' "priority": '|| to_json(r_table.rel_priority) || E',\n';
END IF;
IF r_table.rel_log_dat_tsp IS NOT NULL THEN
v_groupsText = v_groupsText
|| E' "log_data_tablespace": '|| to_json(r_table.rel_log_dat_tsp) || E',\n';
END IF;
IF r_table.rel_log_idx_tsp IS NOT NULL THEN
v_groupsText = v_groupsText
|| E' "log_index_tablespace": '|| to_json(r_table.rel_log_idx_tsp) || E',\n';
END IF;
IF r_table.rel_ignored_triggers IS NOT NULL THEN
-- build the triggers to ignore for the table, if any
v_groupsText = v_groupsText
|| E' "ignored_triggers": [\n';
FOREACH v_trg_name IN ARRAY r_table.rel_ignored_triggers
LOOP
v_groupsText = v_groupsText
|| E' {\n'
|| ' "trigger": ' || to_json(v_trg_name) || E',\n'
|| E' },\n';
END LOOP;
v_groupsText = v_groupsText
|| E' ],\n';
END IF;
v_groupsText = v_groupsText
|| ' "table": ' || to_json(r_table.rel_tblseq) || E',\n'
|| coalesce(' "priority": '|| to_json(r_table.rel_priority) || E',\n', '')
|| coalesce(' "log_data_tablespace": '|| to_json(r_table.rel_log_dat_tsp) || E',\n', '')
|| coalesce(' "log_index_tablespace": '|| to_json(r_table.rel_log_idx_tsp) || E',\n', '')
|| coalesce(' "ignored_triggers": ' || array_to_json(r_table.rel_ignored_triggers) || E',\n', '')
|| E' },\n';
END LOOP;
v_groupsText = v_groupsText
Expand Down Expand Up @@ -6523,8 +6496,8 @@ $_import_groups_conf_prepare$
FROM json_array_elements(r_group.groupJson -> 'tables')
LOOP
-- prepare the array of trigger names for the table
SELECT array_agg("trigger" ORDER BY "trigger") INTO v_ignoredTriggers
FROM json_to_recordset(r_table.tableJson -> 'ignored_triggers') AS x("trigger" TEXT);
SELECT array_agg("value" ORDER BY "value") INTO v_ignoredTriggers
FROM json_array_elements_text(r_table.tableJson -> 'ignored_triggers') AS t;
-- ... and insert
INSERT INTO tmp_app_table(tmp_group, tmp_schema, tmp_tbl_name,
tmp_priority, tmp_log_dat_tsp, tmp_log_idx_tsp, tmp_ignored_triggers)
Expand Down

0 comments on commit 88958d8

Please sign in to comment.