Skip to content

meta_data.json description

Oleg Gurov edited this page Jan 7, 2021 · 18 revisions

Any package (packet) can have a meta_data.json file that defines execution settings.

The meta_data.json contains information about the current packet and provides the ability to send output of db_converter to messenger or other functionality. The current implementation supports only mattermost integration.

General structure of meta_data.json:

{
    "type": < "default" | "read_only" | "no_commit" | "maintenance" | "export_data" >,
    "client_min_messages": < "DEBUG1" | "LOG" | "NOTICE" | "WARNING" | "ERROR" >,
    "export_options": {
        "use_zip": < "yes" | "no" >
        "password": < "random" | "123456" >
    },
    "hook": {
        "type": < "matterhook" | "slack" >,
        "username": text,
        "verbosity": [ "resultset" | "stm_result" | "raise" | "all" ],
        "channel": text,
        "message": text
    },
    "postgresql": {
        "statement_timeout": "180s"
    }
}

The client_min_messages field initializes the corresponding session variable and determines what level of messages will be displayed in the console during packet deployment:

Value Description
ERROR Only errors are displayed
WARNING This mode is used by default. Warnings and errors are displayed.
NOTICE The raise notice is displayed, plus the above
LOG The raise log is displayed, plus the above
DEBUG1...DEBUG5 Debug mode

The postgresql section allows to override settings of section postgresql in db_converter.conf file.

Packet types

Possible values of type field:

Value Action tracker Description
default Yes If the type field is not initialized or has a default value, then a package is tracked in target database during deployment. The entire content of meta_data.json will be written to dbc_packets.meta_data
read_only No A transaction will be opened in SET TRANSACTION READ ONLY mode. This mode can be used to implement notifications when the DB state does not change. When launching a packet of this type, the execution result is not recorded in the target database, i.e. the packet can be launched an unlimited number of times. Read only packet example.
no_commit No A transaction of this packet type will be rolled back. The result of an execution is not recorded. This mode is appropriate for implementing notifications when the state of the database does not change and auxiliary temporary tables are required during the execution of the query.
maintenance No A package of this type can change the database structure and data, but the deployment result is not recorded. This mode is appropriate for implementing periodic database maintenance, for example, clearing old data. See example.
export_data No A transaction will be opened in SET TRANSACTION READ ONLY mode. Deployment result is not recorded to Action tracker. A package of this type should only have SELECT queries. The results of queries will be saved to files of the same name, taking into account the export settings - section export_options. Example of export_data

Hooks

The hook object contains a description of interaction with the messenger. Previously, the matterhook section of db_converter.conf file must be configured, for example:

[matterhook]
url = https://mm.site.org
chat_keys = dbc-dba/973cq47o6tbhtnqwbibdduqkbi

How to set up meta_data.json and incoming hooks in mattermost:

 

 

Hooks verbosity

The verbosity settings allows to customize the notifications as well as the amount of information displayed. For example, some notifications can be addressed to all chat participants or to someone specific, depending on the result of step.

Consider an example of a one-step packet with the following commands:

do $$
begin
    raise notice 'raise notice';
    raise warning 'raise warning'; 
end;
$$;
select version();

The behavior of an output to messenger is determined by the hook.verbosity parameter.

"hook"."verbosity": ["resultset"] - displays the result of queries:

{
    "type": "read_only",
    "hook": {
        "type": "matterhook",
        "username": "db_converter",
        "channel": "dbc-dba",
        "verbosity": ["resultset"],
        "message": "Current PotgreSQL version:"
    }
}

 

 

"hook"."verbosity": ["stm_result"] - displays the result of statements:

 

 

"hook"."verbosity": ["raise"] - send the results of raise commands to output:

 

 

"hook"."verbosity": ["all"] - full output (all of the above cases). The mode is used by default.

 

 

To see the result of raise notice in output, add "client_min_messages": "NOTICE":

{
    ...
    "client_min_messages": "NOTICE",
    "hook": {
        ...
        "verbosity": ["all"]
    }
}

 

 

Clone this wiki locally