PatternANotFollowedByPatternB

The PatternANotFollowedByPatternB Quality Check triggers on changesets in which user-supplied regular expression pattern A is not followed 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 perform negative lookaheads in their changelog.

Learn more about lookaheads and lookbehinds here: Lookahead_assertion

Uses

The PatternANotFollowedByPatternB 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
PatternANotFollowedByPatternB changelog

false

Default value: 0

  • 'INFO' | 0
  • 'MINOR' | 1
  • 'MAJOR' | 2
  • 'CRITICAL' | 3
  • 'BLOCKER' | 4

<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 PatternANotFollowedByPatternB check

To run the PatternANotFollowedByPatternB 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: PatternANotFollowedByPatternB logic: If regular expression pattern X exists then Pattern A must not exist after pattern X.

In this example, you are ensuring that all instances of regular expression pattern X are not followed by regular expression pattern Y. When this check runs successfully, a log will be created that displays all instances when regular expression pattern X are not followed by regular expression pattern Y.

  1. Enable the PatternANotFollowedByPatternB check by running the following command in the CLI:

    liquibase checks enable --check-name=PatternANotFollowedByPatternB
  2. Give your check a short name for easy identification such as RegexNegativeLookAheadCheck. The new RegexNegativeLookAheadCheck check is created from the PatternANotFollowedByPatternB.

    Note: You can use up to 64 alpha-numeric characters in any short name.

  3. 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)
  4. Set the 'PRIMARY_SEARCH_STRING' to a string or a valid regular expression.
    Set it to a regular expression (ALTER|DROP)\s*TABLE.

  5. Set the 'LOOKAHEAD_SEARCH_STRING' to a string or a valid regular expression.
    Set it to a regular expression CREATE\s*SNAPSHOT\s*TABLE.

  6. Set the case sensitivity to true or false.
    Set it to 'CASE_SENSITIVE' false.

  7. Set the 'LOOKAHEAD_MESSAGE'.
    Set it to '<LOOKAHEAD_SEARCH_STRING>' must not follow '<PRIMARY_SEARCH_STRING>'

  8. Set the 'STRIP_COMMENTS' to true or false.
    Set it to true.

    Once successfully run, either of the two resulting reports appear:

    CHANGELOG CHECKS
    ----------------
    Checks completed validation of the changelog and found the following issues:
    
    Check Name:         Pattern a not followed by pattern b (RegexNegativeLookAheadCheck)
    Changeset ID:       createFunction
    Changeset Filepath: changelog.sql
    Check Severity:     INFO (Return code: 0)
    Message:            A match for regular expression '<PRIMARY_SEARCH_STRING>' must not appear before '<LOOKAHEAD_SEARCH_STRING>' was detected in Changeset 'createFunction'.