Skip to content

Commit

Permalink
Add capabilities to save tables groups configurations. Two new emaj_e…
Browse files Browse the repository at this point in the history
…xport_groups_configuration() functions allow to export the tables groups content as a JSON structure, either directly or into a file. Associated import functions will come in a separate patch.
  • Loading branch information
beaud76 committed Jan 23, 2020
1 parent 8ff5066 commit 125972d
Show file tree
Hide file tree
Showing 41 changed files with 1,405 additions and 240 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ E-Maj - Change log
<devel>
------
###Enhancements:###
* Two new emaj_export_groups_configuration() functions allow to export
tables groups configurations as a JSON structure, either directly or into
a file.
* Two new emaj_export_parameters_configuration() functions allow to export
the E-Maj parameters as a JSON structure, either directly or into a file.
* Two new emaj_import_parameters_configuration() functions allow to import
Expand Down
6 changes: 6 additions & 0 deletions docs/en/functionsList.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ General purpose functions
| :ref:`emaj_enable_protection_by_event_triggers | | #.triggers INT |
| <emaj_enable_protection_by_event_triggers>` | | |
+--------------------------------------------------+-------------------------------+---------------------------------------+
| :ref:`emaj_export_groups_configuration | | NULL, | configuration JSON |
| <export_groups_conf>` | | [groups.array TEXT[]] | |
+--------------------------------------------------+-------------------------------+---------------------------------------+
| :ref:`emaj_export_groups_configuration | | file.path TEXT, | #.groups INT |
| <export_groups_conf>` | | [groups.array TEXT[]] | |
+--------------------------------------------------+-------------------------------+---------------------------------------+
| :ref:`emaj_export_parameters_configuration | | parameters JSON |
| <export_param_conf>` | | |
+--------------------------------------------------+-------------------------------+---------------------------------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/en/otherFunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The function returns the number of exported parameters.
If the file path is not supplied, the function directly returns the JSON structure containing the parameters value. This structure looks like this::

{
"comment": "E-Maj parameters, generated from the database <db> with E-Maj version <version> at <date_heure>",
"_comment": "E-Maj parameters, generated from the database <db> with E-Maj version <version> at <date_heure>",
"parameters": [
{
"key": "...",
Expand Down
62 changes: 62 additions & 0 deletions docs/en/otherGroupsFunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,65 @@ Using this function, it is easy to consolidate at once all “*consolidable*”

The *emaj_get_consolidable_rollbacks()* function may be used by *emaj_adm* and *emaj_viewer* roles.

Exporting tables groups configurations
--------------------------------------

A set of functions allow to export tables groups configurations.

.. _export_groups_conf:

Export a tables groups configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Two versions of the *emaj_export_groups_configuration()* function export a description of one or several tables groups as a JSON structure.

A tables groups configuration can be written to a file with::

SELECT emaj_export_groups_configuration('<file.path>', <groups.names.array>);

The file path must be accessible in write mode by the PostgreSQL instance.

The second parameter is optional. It lists in an array the tables groups names to processed. If the parameter is not supplied or is set to NULL, the configuration of all tables groups is exported.

The function returns the number of exported tables groups.

If the file path is not supplied (i.e. is set to NULL), the function directly returns the JSON structure containing the configuration. This structure looks like this::

{
"_comment": "Generated on database <db> with E-Maj version <version> at <date_heure>",
"tables_groups": [
{
"group": "...",
"is_rollbackable": ...,
"comment": "...",
"tables": [
{
"schema": "...",
"table": "...",
"priority": ...,
"log_data_tablespace": "...",
"log_index_tablespace": "...",
"ignored_triggers": [
{
"trigger": "...",
...
},
]
},
{
...
}
],
"sequences": [
{
"schema": "myschema1",
"sequence": "mytbl1",
},
{
...
}
],
},
...
]
}
6 changes: 6 additions & 0 deletions docs/fr/functionsList.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ Fonctions de niveau général
| :ref:`emaj_enable_protection_by_event_triggers | | nb.triggers INT |
| <emaj_enable_protection_by_event_triggers>` | | |
+--------------------------------------------------+-------------------------------+---------------------------------------+
| :ref:`emaj_export_groups_configuration | | NULL, | configuration JSON |
| <export_groups_conf>` | | [tableau.groupes TEXT[]] | |
+--------------------------------------------------+-------------------------------+---------------------------------------+
| :ref:`emaj_export_groups_configuration | | fichier TEXT, | nb.groupes INT |
| <export_groups_conf>` | | [tableau.groupes TEXT[]] | |
+--------------------------------------------------+-------------------------------+---------------------------------------+
| :ref:`emaj_export_parameters_configuration | | paramètres JSON |
| <export_param_conf>` | | |
+--------------------------------------------------+-------------------------------+---------------------------------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/fr/otherFunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ La fonction retourne le nombre de paramètres exportés.
Si le chemin du fichier n’est pas renseigné, la fonction retourne directement la structure JSON contenant les valeurs de paramètres. Cette structure ressemble à ceci ::

{
"comment": "E-Maj parameters, generated from the database <db> with E-Maj version <version> at <date_heure>",
"_comment": "E-Maj parameters, generated from the database <db> with E-Maj version <version> at <date_heure>",
"parameters": [
{
"key": "...",
Expand Down
62 changes: 62 additions & 0 deletions docs/fr/otherGroupsFunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,65 @@ A l'aide de cette fonction, il est ainsi facile de consolider tous les rollbacks

La fonction *emaj_get_consolidable_rollbacks()* est utilisable par les rôles *emaj_adm* et *emaj_viewer*.

Exporter des configurations de groupes de tables
------------------------------------------------

Un jeu de fonctions permet d’exporter des configurations de groupes de tables.

.. _export_groups_conf:

Export d’une configuration de groupes de tables
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Deux versions de la fonction *emaj_export_groups_configuration()* exportent sous forme de structure JSON une description d’un ou plusieurs groupes de tables.

On peut écrire dans un fichier une configuration de groupes de tables par ::

SELECT emaj_export_groups_configuration('<chemin.fichier>', <tableau.noms.groupes>);

Le chemin du fichier doit être accessible en écriture par l’instance PostgreSQL.

Le seconde paramètre, optionnel, liste sous forme d’un tableau les groupes de tables dont on souhaite exporter la configuration. Si le paramètre est absent ou valorisé à NULL, tous les groupes de tables existants sont exportés.

La fonction retourne le nombre de groupes de tables exportés.

Si le chemin du fichier n’est pas renseigné (i.e. est valorisé à NULL), la fonction retourne directement la structure JSON contenant la configuration des groupes de tables. Cette structure ressemble à ceci ::

{
"_comment": "Generated on database <db> with E-Maj version <version> at <date_heure>",
"tables_groups": [
{
"group": "...",
"is_rollbackable": ...,
"comment": "...",
"tables": [
{
"schema": "...",
"table": "...",
"priority": ...,
"log_data_tablespace": "...",
"log_index_tablespace": "...",
"ignored_triggers": [
{
"trigger": "...",
...
},
]
},
{
...
}
],
"sequences": [
{
"schema": "myschema1",
"sequence": "mytbl1",
},
{
...
}
],
},
...
]
}

0 comments on commit 125972d

Please sign in to comment.