NoDbclString

The NoDbclString custom policy check prevents any uppercase or lowercase variations of the string databasechangelog from appearing outside of comments.

regex: (?i)databasechangelog

Step-by-Step

Note: These steps describe how to create the custom policy check. It does not exist by default in Liquibase Pro.

  1. Enter this command into the CLI: 
    liquibase checks customize --check-name=SqlUserDefinedPatternCheck
  2. Give your check a short name for easier identification. In this example we will title the check:
    ForbidDBCLKeyword
  3. Set the Severity to return a code of 0-4 when triggered.
    Options: 'INFO'=0, 'MINOR'=1, 'MAJOR'=2, 'CRITICAL'=3, 'BLOCKER'=4

  4. Set the SEARCH_STRING to this valid regular expression:
    (?i)databasechangelog

  5. Set the MESSAGE for when a match for regular expression <SEARCH_STRING> is found in a Changeset:

    Example: SQL referencing Liquibase tables is not allowed. A match for regular expression <SEARCH_STRING> was detected in Changeset <CHANGESET>

  6. Set STRIP_COMMENTS to true if you want to remove the comments from the output.

    The regex custom policy check is created successfully.

Sample Failing Scripts

Copy
DELETE FROM databasechangelog WHERE condition;
Copy
UPDATE DATABASECHANGELOGHISTORY
SET column1 = value1, column2 = value2, ...
WHERE condition;
Copy
DROP TABLE DATABASECHANGELOGlock;

Sample Error Message

Copy
CHANGELOG CHECKS
----------------
Checks completed validation of the changelog and found the following issues:

Check Name:         Check for specific patterns in sql (ForbidDBCLKeyword)
Changeset ID:       myChangeset
Changeset Filepath: root_changelog.xml
Check Severity:     BLOCKER (Return code: 4)
Message:            A match for regular expression (?i)databasechangelog was detected in Changeset myChangeset.