我希望 jOOQ 根據我提供的 liquibase 模式 xml 檔案自動生成代碼(而不是基于資料庫連接)。如果我更改 liquibase xml 檔案中的某些內容,更改會反映在資料庫中,但我無法使用新的自動生成代碼。我必須運行兩次 mvn clean compile 才能讓 jOOQ 了解更改。
我的 pom.xml 的生成器部分看起來像這樣。請幫忙:
<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.extensions.liquibase.LiquibaseDatabase</name>
<name>org.jooq.meta.postgres.PostgresDatabase</name>
<properties>
<!-- Specify the classpath location of your XML, YAML, or JSON script. -->
<property>
<key>scripts</key>
<value>liquibase-outputChangeLog.xml</value>
</property>
<!-- Whether you want to include liquibase tables in generated output
- false (default)
- true: includes DATABASECHANGELOG and DATABASECHANGELOGLOCK tables -->
<property>
<key>includeLiquibaseTables</key>
<value>true</value>
</property>
<!-- Properties prefixed "database." will be passed on to the liquibase.database.Database class
if a matching setter is found -->
<!-- The property "changeLogParameters.contexts" will be passed on to the
liquibase.database.Database.update() call (jOOQ 3.13.2 ).
See https://www.liquibase.org/documentation/contexts.html -->
<property>
<key>changeLogParameters.contexts</key>
<value>!test</value>
</property>
</properties>
<inputSchema>public</inputSchema>
</database>
</generator>
</configuration>
uj5u.com熱心網友回復:
你的問題是關于
通過PostgresDatabase在 之外添加LiquibaseDatabase,您只需覆寫該元素的LiquibaseDatabase配置。<name/>您不能指定其中的多個。
你試圖解決的問題
請查看 jOOQ 的檔案LiquibaseDatabase。它提到該scripts屬性應該描述遷移檔案的類路徑位置,而不是相對路徑位置,例如
<!-- Specify the classpath location of your XML, YAML, or JSON script. -->
<property>
<key>scripts</key>
<value>/database.xml</value>
</property>
(注意開頭的斜線)。從 jOOQ 3.16.5 開始,它解決了 Liquibase 本身的不兼容更改(請參閱#13031),您現在可以使用相對路徑以及rootPath從 Liquibase 4.0 開始需要的附加規范:
<!-- Specify the root path, e.g. a path in your Maven directory layout -->
<property>
<key>rootPath</key>
<value>${basedir}/src/main/resources</value>
</property>
<!-- Specify the relative path location of your XML, YAML, or JSON script. -->
<property>
<key>scripts</key>
<value>database.xml</value>
</property>
使用實際資料庫的更長期解決方案
雖然LiquibaseDatabase當您的資料庫很簡單時可以幫助加快速度,但一旦您使用供應商特定的功能(存盤程序、資料型別等),這種方法就不再可行了。在實際的 PostgreSQL 資料庫上運行遷移,然后從中生成代碼會好得多。您可以為此使用 testcontainers,如本博文中所述。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/445984.html
標籤:弹簧靴 行家 液基 乔克 jooq-codegen-maven
上一篇:在OWM-JAPI中獲取天氣
