如何使用 liquibase 腳本使 jooq 自動生成器運行,然后在 spring boot 啟動時進行 liquibase 遷移,而不是 mvn clean compile?
我希望 jooq 自動生成器基于 liquibase 模式運行,然后我希望 liquibase 遷移在 spring boot 啟動時運行,但目前它在運行 mvn clean compile 時運行。我希望像“Acquired Change Lock”這樣的日志在應用程式啟動后出現,而不是在 mvn clean compile 上。
這是 pom.xml 摘錄:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>generate-resources</phase>
<configuration>
<propertyFile>src/main/resources/liquibase.properties</propertyFile>
<changeLogFile>src/main/resources/liquibase-outputChangeLog.xml</changeLogFile>
<driver>org.postgresql.Driver</driver>
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.13.4</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.12</version>
</dependency>
</dependencies>
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.16.3.xsd">
<jdbc>
<driver>org.postgresql.Driver</driver>
<url>${spring.datasource.url}</url>
<user>${spring.datasource.username}</user>
<password>${spring.datasource.password}</password>
</jdbc>
<generator>
<database>
<name>org.jooq.meta.postgres.PostgresDatabase</name>
<includes>.*</includes>
<excludes></excludes>
<inputSchema>public</inputSchema>
</database>
<target>
<packageName>com.slb.pps.azure.jooqGenerated</packageName>
<directory>target/generated-sources/jooq</directory>
</target>
</generator>
</configuration>
</plugin>
請幫我除錯一下。讓我知道是否需要任何其他資訊。
uj5u.com熱心網友回復:
您的 Maven 配置在您的開發和構建環境中很有用,在這些環境中您依賴實時資料庫和資料庫連接:
- jOOQ 代碼生成
- 建筑
- 集成測驗(我懷疑?)
但這與您的生產資料庫使用不同,您最好以編程方式運行 Liquibase,嵌入到您的應用程式中。這不是運行生產遷移的唯一選擇,而是我推薦的選擇。這是 Liquibase 關于該主題的官方資源,可幫助您做出明智的決定: https ://www.liquibase.com/blog/3-ways-to-run-liquibase
這是另一個資源,展示了如何將 jOOQ 的代碼生成與測驗容器一起使用,而不是實時資料庫,這可能有助于更好地分離構建和生產問題: https ://blog.jooq.org/using-testcontainers-to-generate-jooq -代碼/
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/446965.html
