【问题标题】:How to introduce liquibase in midle of spring boot maven based project如何在基于 Spring Boot Maven 的项目中引入 liquibase
【发布时间】:2022-01-06 11:58:58
【问题描述】:

`我已经在运行项目并尝试在项目中间引入 liquibase。 这是基于 Spring Boot Maven 的项目。

我正在执行步骤。

1.liquibase.properties

url=jdbc:postgresql://localhost:5432/cc
username=postgres
password=deadline123
driver=org.postgresql.Driver
outputChangeLogFile=src/main/resources/db/changelog/db.changelog-master.yaml
runOnChange=true
referenceUrl=jdbc:postgresql://localhost:5432/cc
referenceUsername=postgres
referencePassword=deadline123
changelogFile=src/main/resources/db/changelog/db.changelog-master.yaml
diffChangeLogFile=src/main/resources/diff.yaml
  1. 运行命令生成当前数据库状态的变更日志 mvn liquibase:generateChangeLog
  2. 然后运行命令同步更改日志并在数据库中创建条目 mvn liquibase:changelogSync
  3. 启动我的应用程序但它抛出错误关系已经存在。我不明白为什么 liquibase 正在执行已经执行的变更集?我正在使用 liquibase 4.6.3

【问题讨论】:

    标签: java postgresql spring-boot maven liquibase


    【解决方案1】:

    Liquibase 不会将更改与您的实际表进行比较,它只会跟踪已执行的更改集(它会为名为 databasechangelog 的表创建另一个表)。

    话虽如此,您必须确保 liquibase 执行您的变更集,前提条件是“如果有任何失败,请将其标记为已执行”。可以这样实现:

    <preconditions onFail="MARK_RAN">
        <not>
            <tableExists tableName="person"/>
        </not>
    </preconditions>
    

    这个例子以及更多信息可以在https://www.liquibase.com/blog/adding-liquibase-on-an-existing-project找到

    【讨论】:

      【解决方案2】:

      问题在于文件路径src/main/resources/db/changelog/db.changelog-master.yaml

      liquibase:changelogSync 如上所述在日志同步中添加文件路径,liquibae 在启动时实际上需要classpath classpath:/db/changelog/db.changelog-master.yaml

      【讨论】:

        猜你喜欢
        • 2019-08-30
        • 2020-08-25
        • 1970-01-01
        • 1970-01-01
        • 2019-03-02
        • 1970-01-01
        • 2018-11-29
        • 2018-03-05
        • 2021-09-09
        相关资源
        最近更新 更多