You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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}"
      }

错误原因

  1. 拼写错误:preConfition应为preConditions,拼写错误导致Liquibase无法识别该配置节点
  2. 结构错误:原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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 01:20:01