簡體   English   中英

如何在 spring 引導 maven 項目的中間引入 liquibase

[英]How to introduce liquibase in midle of spring boot maven based project

`我已經在運行項目並嘗試在項目中間引入 liquibase。 這是基於 spring 引導 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. 運行命令為當前 DB state mvn liquibase:generateChangeLog生成更改日志
  2. 然后運行命令同步更改日志並在 DB mvn liquibase:changelogSync中創建條目
  3. 啟動我的應用程序,但它拋出錯誤關系已經存在。 我不明白為什么 liquibase 正在執行已經執行的變更集? 我正在使用 liquibase 4.6.3

Liquibase 不會將更改與您的實際表進行比較,它只會跟蹤已經執行的更改集(它會為名為databasechangelog的表創建另一個表)。

話雖如此,您必須確保 liquibase 執行您的變更集,前提條件是“如果有任何失敗,請將其標記為已執行”。 可以這樣實現:

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

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

問題出在文件路徑src/main/resources/db/changelog/db.changelog-master.yaml

liquibase:changelogSync在日志同步中添加文件路徑,並且liquibae在啟動時實際上采用classpath classpath:/db/changelog/db.changelog-master.yaml

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM