Verify naming conventions in your database

The ObjectNameMustMatch and ObjectNameMustNotMatch policy checks 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.

Two verifying policy checks

You can use two policy checks to verify whether objects in your database:

  • ObjectNameMustMatch specifies a positive search.

  • ObjectNameMustNotMatch specifies a negative search.

Liquibase supports this check on the following objects:

  • TABLE

  • COLUMN

  • SEQUENCE

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.

Procedure

1

Create a new check with the following command:

liquibase checks copy --check-name=[ObjectNameMustMatch|ObjectNameMustNotMatch]
2

Enter a short name into the CLI.

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.:

New check 'ObjectNameMustMatchMountainTimeZone' created from 'ObjectNameMustMatch'

3

Verify naming conventions in your database 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 operator to any of the below options

In this example, we will use CONTAINS: MT to search for any instance of Mountain time zone.

Options: STARTS_WITH, ENDS_WITH, CONTAINS, REGEXP) [STARTS_WITH]:

5

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

6

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

7

Set the case sensitivity to true or false in the CLI

Set 'CASE_SENSITIVE' (options: true, false) [true]:

8

To validate your changelog check, run the following command

liquibase checks run