What are preconditions?
Last updated: November 18, 2025
Preconditions are tags you add to your changelog or individual changesets to control the execution of an update based on the state of the database. Preconditions let you specify security and standardization requirements for your changesets. If a precondition on a changeset fails, Liquibase does not deploy that changeset.
Example failure on a changelog
Unexpected error running Liquibase: Validation Failed:
1 preconditions failed
myChangelog.xml : DBMS Precondition failed: expected oracle, got postgresqlChangelog syntax
Example error on a changelog
Changelog syntax for multiple preconditions
Example warning on a changelog
customPrecondition syntax
Available preconditions
The examples of preconditions shown in the table don't include the schemaName attribute. It is best practice not to keep the schemaName in the changeset and rely on the default schema except when you don't want to create something in the default schema.
Additionally, you can include the onError or onFail attributes with the WARN, HALT, CONTINUE, or MARK_RAN value in the preconditions tag, however, the CONTINUE and MARK_RAN options can only be applied to preconditions inside a changeset.
changeLogPropertyDefined
Checks whether given changelogattribute is present. It fails if the value is not the same as given.
Attribute | Description | Requirement |
| The name of the property to check. | Required |
| The required value for a given property. | Optional |
changeLogPropertyDefined syntax
changeSetExecuted
Defines if the specified changeset has already been executed.
Attribute | Description | Requirement |
| The changeset id. | Required |
| The changeset author. | Required |
| The file name (including searchPath relative path) of the changeset. | Required |
changeSetExecuted syntax
columnExists
Defines if the specified column exists in the database.
Note: Liquibase initially tries to run this precondition with a resource-efficient database query. If it fails, it creates a snapshot of your database, which may impact performance.
Attribute | Description | Requirement |
| The name of the column. | Required |
| The name of the column's table. | Required |
| The name of the table's schema. | Optional |
columnExists syntax
dbms
Defines if the database executed against matches the type specified.
Note: The dbms precondition is not available for formatted SQL.
Attribute | Description | Requirement |
| The type of database expected. Multiple dbms values can be specified using comma-separated values. For a list of valid values, see | Required |
dbms syntax
expectedQuotingStrategy
Controls how object names are quoted in the SQL files generated by Liquibase and used in calls to the database. For more information, see objectQuotingStrategy.
Attribute | Description | Requirement |
| The object quoting strategy. Valid values are
,
, and
. | Required |
expectedQuotingStrategy syntax
foreignKeyConstraintExists
Defines if the specified foreign key exists in a table in the database.
Note: Running this precondition always creates a snapshot of your database, which may impact performance.
Attribute | Description | Requirement |
| The name of the foreign key. | Required |
| The name of the table the foreign key is in. | Required
in 4.7.0+ |
| The name of the foreign key's schema. | Optional |
foreignKeyConstraintExists syntax
indexExists
Defines if the specified index exists in the database. You can either specify the indexName attribute or tableName and columnNames attributes.
Note: There are a few databases where the indexName is not unique, which is why both indexName and tableName can be used.
Note: Running this precondition always creates a snapshot of your database, which may impact performance.
Attribute | Description | Requirement |
| The name of the index. | Optional |
| The name of the column. | Optional |
| The name of the table. | Optional |
| The name of the index's schema. | Optional |
indexExists syntax
primaryKeyExists
Defines if the specified primary key exists in the database.
Note: Running this precondition always creates a snapshot of your database, which may impact performance.
Attribute | Description | Requirement |
| The name of the primary key constraint. | Either
or
is
required |
| The name of the table containing primary key. | Either Note: On DB2, H2, HSQLDB, MySQL, and SQLite, |
| The name of the primary key's schema. | Optional |
primaryKeyExists syntax
rowCount
Checks that the number of rows in a table matches an expected value.
Attribute | Description | Requirement |
| The number of rows the user expects in a table. | Required |
| The name of the column's table. | Required |
rowCount syntax
runningAs
Defines if the database user executed under matches the username specified.
Note: The runningAs precondition is not available for formatted SQL.
Attribute | Description | Requirement |
| The database user script which is expected to run as. | Required |
runningAs syntax
sequenceExists
Defines if the specified sequence exists in the database.
Note: If you use PostgreSQL, Liquibase initially tries to run this precondition with a resource-efficient database query. If it fails, it creates a snapshot of your database, which may impact performance. On other databases, Liquibase always creates a snapshot.
Attribute | Description | Requirement |
| The name of the sequence. | Required |
| The name of the sequence's schema. | Optional |
sequenceExists syntax
sqlCheck
Executes an SQL string and checks the returned value. The SQL must return a single row with a single value.
To check a number of rows, use the
countSQL function.To check for ranges of values, perform the check in the SQL and return a value that can be easily compared against.
Attribute | Description | Requirement |
| The value to compare the SQL result to. | Required |
| In JSON and YAML changelogs, the SQL statement to run. In XML changelogs, insert the SQL statement directly within the | Required |
sqlCheck syntax
tableExists
Defines if the specified table exists in the database.
Note: Running this precondition always creates a snapshot of your database, which may impact performance.
Attribute | Description | Requirement |
| The name of the table. | Required |
| The name of the table's schema. | Optional |
tableExists syntax
--changeset your.name:1
--preconditions onFail:MARK_RAN
--precondition-table-exists table:table1 schema:12345
create table table2 (
id int primary key
);
Note: tableExists is supported for SQL changelogs in Liquibase 4.27.0 and later.
tableIsEmpty
Checks whether the specified table is empty.
Attribute | Description | Requirement |
| The name of the table. | Required |
| The name of the database catalog. | Optional |
| The name of the database schema. | Optional |
tableIsEmpty syntax
uniqueConstraintExists
Checks for the existence of unique constraints before running the update. (since Liquibase 4.9.0)
Note: Running this precondition always creates a snapshot of your database, which may impact performance.
Attribute | Description | Requirement |
| The name of the column's table. | Required |
| The name of the column. | Optional |
| The name of the unique constraint. | Optional |
uniqueConstraintExists syntax
viewExists
Defines if the specified view exists in the database.
Note: Running this precondition always creates a snapshot of your database, which may impact performance.
Attribute | Description | Requirement |
| The name of the view. | Required |
| The name of the view's schema. | Optional |
viewExists syntax
Note: viewExists is supported for SQL changelogs in Liquibase 4.27.0 and later.
--changeset your.name:1
--preconditions onFail:MARK_RAN
--precondition-view-exists view:view1 schema:12345
create table table1 (
id int primary key
);
customPrecondition
Can be created by adding a class that implements the liquibase.precondition.CustomPrecondition interface. Parameters on custom classes are set through reflection based on the <param> sub-tags. Pass parameters as strings to the custom precondition.
Attribute | Description | Requirement |
| The name of the custom precondition class. | Required |
<param> sub-tag
The parameter to pass to the custom precondition.
Attribute | Description | Requirement |
| The name of the parameter to set. | Required |
| A string value to set parameter to. | Required |