How to make jooq auto generator to run using liquibase script and then liquibase migration on spring boot startup instead of mvn clean compile?
I want jooq auto generator to run on basis of liquibase schema and then I want liquibase migration to run on spring boot startup but currently it runs on running mvn clean compile. I want the logs like "Acquired Change Lock" to appear after Application startup and not on mvn clean compile.
This is the pom.xml excerpt:
<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>
Please help me debug this. Let me know if any other information is needed.
CodePudding user response:
Your Maven configuration is useful in your development and build environments, where you depend on a live database and database connection for:
- jOOQ code generation
- Building
- Integration testing (I suspect?)
But that's different from your production database usage, where you're probably better off running Liquibase programmatically, embedded in your application. That's not the only option to run production migrations, but the one I'd recommend. Here's an official resource on the topic by Liquibase to help you make an informed decision: https://www.liquibase.com/blog/3-ways-to-run-liquibase
And here's another resource showing how to use jOOQ's code generation along with testcontainers, instead of a live database, which might help better separate build and production concerns: https://blog.jooq.org/using-testcontainers-to-generate-jooq-code/