PatternAPrecededByPatternB
The PatternAPrecededByPatternB
Policy Check triggers on changesets in which user-supplied regular expression pattern A is preceded by the user-supplied regular expression pattern B.
This check is pre-configured, so users only need to supply the patterns and do not have to manually write regular expressions to look behind in their changelog.
Uses
The PatternAPrecededByPatternB
check can be used to confirm conditions within the changelog. This check allows you to check for specific patterns in your changelog and then produce a logged record of changeset structure when certain conditions are met. When it is executed successfully the checks message is logged to the console and logs as proof that changesets conform to specific standards.
Short Name | Scope | Enabled | Severity | Customization | Description |
---|---|---|---|---|---|
PatternAPrecededByPatternB
|
changelog |
false |
Default value: 0
|
<None> |
This check is pre-configured, so users only need to supply the patterns and do not have to manually write regular expressions to perform negative lookaheads in their changelog. |
Run the PatternAPrecededByPatternB check
To run the PatternAPrecededByPatternB
check, ensure you have a Liquibase Pro license and the checks-scope
property includes changelog
. The checks-scope parameter is set in the default properties file, environment variable, or any standard method.
Tip: PatternAPrecededByPatternB
logic: If regular expression pattern X exists then Pattern A must exist before pattern X.
In this example, you are ensuring that a backup of a specific table is taken before any DROP TABLE or ALTER TABLE command runs.
- Enable the
PatternAPrecededByPatternB
check by running the following command in the CLI:liquibase checks copy --check-name=PatternAPrecededByPatternBCheck
- Give your check a short name for easy identification such as
AlterAndDropTableMustIncludeBackup
. The newAlterTableMustIncludeBackup
check is created from thePatternAPrecededByPatternBCheck
.Note: You can use up to 64 alpha-numeric characters in any short name.
-
In the CLI, set the Severity to return a code of 0-4 when the check is triggered. Set the severity to 0.
Your options are:'INFO'|0, 'MINOR'|1, 'MAJOR'|2, 'CRITICAL'|3, 'BLOCKER'|4)
-
Set the
'PRIMARY_SEARCH_STRING'
to a string or a valid regular expression.
Set it to a regular expression(ALTER|DROP)\s*TABLE
. -
Set the
'LOOKBEHIND_SEARCH_STRING'
to a string or a valid regular expression.
Set it to a regular expressionCREATE\s*SNAPSHOT\s*TABLE
. -
Set the case sensitivity to true or false.
Set it to'CASE_SENSITIVE' false
. -
Set the 'LOOKBEHIND_MESSAGE'.
Set it to'<LOOKBEHIND_SEARCH_STRING>'
must appear before'<PRIMARY_SEARCH_STRING>'
-
Set the 'STRIP_COMMENTS' to
true
orfalse
.
Set it totrue
.
Once successfully run, either of the two resulting reports appear:
Results if the check passes
--liquibase formatted sql
--changeset user_name:01
CREATE SNAPSHOT TABLE `sample_dataset_01.table_01-snapshot`
CLONE `sample_dataset_01.table_01`;
ALTER TABLE sample_dataset_01.table_01 add column col_new smallint;
Results if the check fails
--liquibase formatted sql
--changeset user_name:01
ALTER TABLE sample_dataset_01.table_01 add column col_new smallint;