Liquibase XML转YAML配置异常:preConditions被忽略
Liquibase YAML配置preConditions失效问题修复
问题情况
原XML配置可正常运行,转换为YAML后,Liquibase忽略preConditions直接执行changes,即便application.properties中service.entities.migration.enabled值设为false,自定义变更仍会执行。
原XML配置
<?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" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd"> <changeSet id="send_service_entities" author="test"> <preConditions onFail="CONTINUE"> <changeLogPropertyDefined property="service.entities.migration.enabled" value="true"/> </preConditions> <comment>Sending service entities</comment> <customChange class="com.testproject.migration.v2.ServiceEntitiesMigrationCustomChange"> <param name="serviceName" value="${spring.application.name}"/> </customChange> </changeSet> </databaseChangeLog>
错误的YAML配置
databaseChangeLog: - changeSet: id: send_service_entities author: test comment: "Sending service entities" preConfition: - onFail: CONTINUE - changeLogPropertyDefined: property: service.entities.migration.enabled value: true changes: - customChange : { "class": "com.testproject.migration.v2.ServiceEntitiesMigrationCustomChange", "serviceName": "${spring.application.name}" }
错误原因
- 拼写错误:
preConfition应为preConditions,拼写错误导致Liquibase无法识别该配置节点 - 结构错误:原XML中
onFail是preConditions的属性,而非独立数组元素;错误YAML将其拆分为数组项,破坏了配置逻辑结构,导致preConditions规则不生效
正确的YAML配置
databaseChangeLog: - changeSet: id: send_service_entities author: test comment: "Sending service entities" preConditions: onFail: CONTINUE changeLogPropertyDefined: property: service.entities.migration.enabled value: true changes: - customChange: class: "com.testproject.migration.v2.ServiceEntitiesMigrationCustomChange" param: name: "serviceName" value: "${spring.application.name}"
内容的提问来源于stack exchange,提问作者Maxim
相关产品推荐
相关产品推荐

