Applies to:
- Liquibase Pro
- Liquibase Open Source (Community)
Environment Conditions:
- Any Liquibase version
Summary:
By default, when an error occurs when deploying changesets, Liquibase will stop and not attempt to deploy any changesets after the error, causing the deployment to end in a failure. In some scenarios, a user may not want an error on a changeset to cause the deployment to fail. Instead, the user would like for the deployment to skip over the failed changeset and continue applying changesets.
Usually, the "failOnError" setting is used for changesets meant for logging or reporting. We strongly advise thinking of the changeset outcome when considering using this setting, such as if the changeset should cause the deployment to stop or the application to fail.
If the failed changeset has "failOnError" set to false, it will not be added to the DATABASECHANGELOG table and is still an eligible changeset to deploy, so the root issue for why the changeset is failing needs to be fixed. Otherwise, the changeset will not deploy.
How to allow a changeset to fail
There are two options for allowing this behavior. One is the built-in Liquibase attribute, and the other is using SQL (this depends on each database).
Liquibase Attribute
In your changeset, add the failOnError attribute.
Formatted SQL example
--changeset liquibase_support:1 failOnError:false
...
XML example
<changeSet id="1" author="liquibase_support" failOnError="false">
...
YAML example
databaseChangeLog:
- changeSet:
id: 1
author: liquibase_support
failOnError: false
changes:
- createTable:
...
JSON example
{
"changeSet": {
"id": "1",
"author": "liquibase_support",
"failOnError": "false",
"changes": [
{
...
Example:
-- liquibase formatted sql
-- changeset liquibase_support:1 failOnError:false
select * from USERS;
-- rollback not required
In the above example, if the table USERS does not exist, that changeset will fail when deploying to the database; however, "failOnError" will cause the changeset to still be "marked" as successful.
Using SQL to allow a script to fail
Depending on the database, you can use the Pro feature runWith, to execute the SQL script via the native executor.
As an example, Oracle has the command WHENEVER SQLERROR CONTINUE, so in combination with runWith:sqlplus, you can have a changeset using that command.
Example
-- liquibase formatted sql
-- changeset liquibase:2 runWith:sqlplus
WHENEVER SQLERROR CONTINUE;
CREATE TABLE trigger (
id NUMBER NOT NULL,
description VARCHAR2(50) NOT NULL
);
Comments
0 comments
Article is closed for comments.