即使抛出错误,如何继续执行 Liquibase 脚本?

How to continue execution of Liquibase script even though there is error thrown?

我正在使用 MySQL 数据库。我调用存储过程 3 次以插入 3 条记录。以下是相同的示例。

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:pro="http://www.liquibase.org/xml/ns/pro"
   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.10.xsd
   http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-3.10.xsd">
    <changeSet id="Demo" author="rambo" runOnChange="true">
        <sql splitStatements="true">            
            CALL insert_animal(NULL, 'Cat', 'Cat', NULL, 0, '', '');
            CALL insert_animal(NULL, 'Mouse', 'Mouse', NULL, 0, '', '');
            CALL insert_animal(NULL, 'Dog', 'Dog', NULL, 0, '', '');            
        </sql>
        <rollback/>
    </changeSet>
</databaseChangeLog>

现在,当我更新上面的脚本以添加第 4 只动物时,我得到了错误,基本上它说存在名为 Cat 的记录并且脚本执行停止。

我想做的是,我想继续执行,即使插入任何动物的 SP 调用失败,因为它是重复的。

我是 liquibase 的新手,正在寻求一些建议。

您试图以错误的方式使用 liquibase。变更集旨在仅写入一次,并且在将其应用于数据库后永远不会更改。如果您需要向现有变更集添加新内容 - 只需创建新的即可。此规则也不例外,特别是如果您已经提交了更改。 实际上,只有一个例外——如果您在自己的数据库上测试变更集并且它不满足要求。在这种情况下,您应该从 databasechangelog table 中删除相应的行,手动 return 数据库架构到以前的状态,更新变更集并将其再次应用于数据库。 此外,您永远不应使用 liquibase 将新数据添加到 tables。 Liquibase 旨在更改模式状态,而不是数据库数据。如果打破这个规则,一路上会遇到很多问题,因为数据是一个经常变化的对象。应用 liquibase 更改后,使用普通 sql 进行数据迁移。