Verify naming conventions in your database

The Multiple Objects Policy Checks feature allows you to verify whether objects in your database adhere to naming conventions you specify. You can use it to test multiple types of objects at the same time, rather than creating individual checks for each one.

The name of the multiple objects check depends on what kind of search you want to make:

Liquibase supports this check on the following objects:

  • TABLE
  • COLUMN
  • SEQUENCE

Using the multiple objects check

  1. Create a new multiple objects check with the following command:

    liquibase checks copy --check-name=[ObjectNameMustMatch|ObjectNameMustNotMatch]
  2. Liquibase prompts you to provide a short name. A short name is a descriptive name that indicates what you want the check to search for in the database or changelog.
    In this example we will provide ObjectNameMustMatchMountainTimeZoneinUS as the short name because we will be searching for any instances of any objects with Mountain Time Zone that are within the US. You are limited to 64 alpha-numeric characters only in the short name.
    The CLI will indicate that the new check was created successfully.:

  3. New check 'ObjectNameMustMatchMountainTimeZone' created from 'ObjectNameMustMatch'
    
  4. Set the Severity to return a code of 0-4 when triggered.
    Options: 'INFO'=0, 'MINOR'=1, 'MAJOR'=2, 'CRITICAL'=3, 'BLOCKER'=4

  5. Set the operator to any of the below options. In this example we will use CONTAINS: MT to search for any instance of Mountain time zone.

  6. Options: STARTS_WITH, ENDS_WITH, CONTAINS, REGEXP) [STARTS_WITH]:
  7. Set the search string to a string or valid regular expression. In this example we will search for the US states string to find any US states in the Mountain Time Zone.

    Options: a string, or a valid regular expression) : helloworld

  8. Set the OBJECT_TYPES to check for and separate them by commas. In this example we will use SEQUENCE.

    Options: TABLE, COLUMN, SEQUENCE) : table,column

  9. Set the case sensitivity to true or false in the CLI:

    Set 'CASE_SENSITIVE' (options: true, false)  [true]:
  10. To validate your changelog with the multiple objects check, run the following command:

    liquibase checks run

Multiple objects check attributes

Parameter Type Description Customization Default
OPERATOR String/enum

The location to look for the provided SEARCH_STRING value

  • STARTS_WITH – Value of SEARCH_STRING should be found at the beginning of the table.
  • ENDS_WITH – Value of SEARCH_STRING should be found at the end of the table.
  • CONTAINS – Value of SEARCH_STRING can be anywhere in the table.
  • REGEXP – Value of SEARCH_STRING is a regexp that should be matched.

STARTS_WITH

SEARCH_STRING String/enum

The substring or regular expression to match with the one in the changelog file. Cannot be empty.

Must be true or false.

None
CASE_SENSITIVE String/enum Set how the SearchString is processed

User entry of true or false is accepted case-insensitively

When operator=REGEXP, CASE_SENSITIVE prompt is not shown

true

Note: Liquibase uses the java.util.regex engine to match regular expressions.

Related links