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 |
| String/enum | The location to look for the provided |
– Value of
should be found at the beginning of the table.
– Value of
should be found at the end of the table.
– Value of
can be anywhere in the table.
– Value of
is a regexp that should be matched. |
|
| String/enum | The substring or regular expression to match with the one in the changelog file. Cannot be empty. | Must be | None |
| String/enum | Set how the
is processed | User entry of When |
|
Note: Liquibase uses the java.util.regex engine to match regular expressions.
Procedure
Create a new check with the following command:
liquibase checks copy --check-name=[ObjectNameMustMatch|ObjectNameMustNotMatch]
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'
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
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]:
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
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
Set the case sensitivity to true or false in the CLI
Set 'CASE_SENSITIVE' (options: true, false) [true]:
To validate your changelog check, run the following command
liquibase checks run