Skip to content

Commit

Permalink
chore: Use testcontainers maven plugin for the generation of jooq code
Browse files Browse the repository at this point in the history
  • Loading branch information
juherr committed Jul 16, 2023
1 parent c49d0c0 commit 8b8e2ec
Showing 1 changed file with 111 additions and 128 deletions.
239 changes: 111 additions & 128 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@
<jetty.version>10.0.14</jetty.version>
<lombok.version>1.18.28</lombok.version>
<jackson.version>2.15.2</jackson.version>
<testcontainers.version>1.18.3</testcontainers.version>

<plugin.license-maven.version>4.2</plugin.license-maven.version>
<plugin.testcontainers-jooq-codegen.version>0.0.2</plugin.testcontainers-jooq-codegen.version>

<!-- In Mysql: schema == database (http://dev.mysql.com/doc/refman/5.6/en/glossary.html#glos_schema) -->
<jdbcUrl>jdbc:mysql://${db.ip}:${db.port}/${db.schema}?useSSL=true&amp;serverTimezone=UTC</jdbcUrl>
<db.user>steve</db.user>
<db.password>changeme</db.password>
<db.schema>stevedb</db.schema>
<db.driver>com.mysql.cj.jdbc.Driver</db.driver>
</properties>

<profiles>
Expand Down Expand Up @@ -316,141 +321,119 @@
</plugin>

<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>7.15.0</version>

<!-- Must be in the same phase as Jooq -->
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>migrate</goal>
</goals>
</execution>
</executions>

<configuration>
<!-- https://github.com/steve-community/steve/issues/157 -->
<initSql>SET default_storage_engine=InnoDB;</initSql>
<!-- we need this because of extensions. they have a higher version number
namespace reserved (e.g. 8.x.x). new migrations in core version should
be executed in the extended version as well -->
<outOfOrder>true</outOfOrder>

<!-- Because maven produces this warning after upgrading from 4.2.0 to 5.1.0:
[WARNING] Could not find schema history table `stevedb`.`flyway_schema_history`, but found
`stevedb`.`schema_version` instead. You are seeing this message because Flyway changed its
default for flyway.table in version 5.0.0 to flyway_schema_history and you are still relying
on the old default (schema_version). Set flyway.table=schema_version in your configuration to
fix this. This fallback mechanism will be removed in Flyway 6.0.0. -->
<table>schema_version</table>

<cleanDisabled>true</cleanDisabled>
<driver>com.mysql.cj.jdbc.Driver</driver>
<url>${jdbcUrl}</url>
<user>${db.user}</user>
<password>${db.password}</password>
<schemas>
<schema>${db.schema}</schema>
</schemas>
<locations>
<location>filesystem:src/main/resources/db/migration</location>
</locations>
</configuration>
</plugin>

<plugin>
<!-- Specify the maven code generator plugin -->
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>${jooq.version}</version>

<!-- The plugin should hook into the generate goal -->
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>

<!-- Manage the plugin's dependency -->
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-jooq-codegen-maven-plugin</artifactId>
<version>${plugin.testcontainers-jooq-codegen.version}</version>
<dependencies>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
<version>${jooq.version}</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen</artifactId>
<version>${jooq.version}</version>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<version>${testcontainers.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.jdbc.version}</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen</artifactId>
<version>${jooq.version}</version>
</dependency>
</dependencies>

<!-- http://www.jooq.org/doc/3.5/manual/code-generation/codegen-configuration/
http://www.jooq.org/doc/3.5/manual/code-generation/codegen-advanced/ -->
<configuration>
<jdbc>
<driver>com.mysql.cj.jdbc.Driver</driver>
<url>${jdbcUrl}</url>
<user>${db.user}</user>
<password>${db.password}</password>
</jdbc>

<generator>
<database>
<name>org.jooq.meta.mysql.MySQLDatabase</name>
<includes>.*</includes>
<excludes/>
<inputSchema>${db.schema}</inputSchema>
<unsignedTypes>false</unsignedTypes>

<forcedTypes>
<forcedType>
<name>BOOLEAN</name>
<!-- https://github.com/jOOQ/jOOQ/issues/7719 -->
<includeTypes>(?i:(TINY|SMALL|MEDIUM|BIG)?INT(UNSIGNED)?\(1\))</includeTypes>
</forcedType>
<forcedType>
<name>BOOLEAN</name>
<includeExpression>.*\.OCPP_TAG_ACTIVITY\.(IN_TRANSACTION|BLOCKED)</includeExpression>
</forcedType>
<forcedType>
<userType>org.joda.time.DateTime</userType>
<converter>de.rwth.idsg.steve.utils.DateTimeConverter</converter>
<includeExpression>.*</includeExpression>
<includeTypes>.*(TIMESTAMP|DATETIME).*</includeTypes>
</forcedType>
<forcedType>
<userType>org.joda.time.LocalDate</userType>
<converter>de.rwth.idsg.steve.utils.DateConverter</converter>
<includeExpression>.*\.BIRTH_DAY</includeExpression>
<includeTypes>.*(DATE).*</includeTypes>
</forcedType>
</forcedTypes>
</database>
<generate>
<fluentSetters>true</fluentSetters>
<!-- https://www.jooq.org/doc/3.14/manual/code-generation/codegen-advanced/codegen-config-generate/codegen-generate-java-time-types/
JOOQ switching to java.time data types messes up our converters since we use JodaTime.
Until we as a project completely switch to java.time, I am disabling it. -->
<javaTimeTypes>false</javaTimeTypes>
</generate>

<target>
<packageName>jooq.steve.db</packageName>
<directory>${project.build.directory}/generated-sources</directory>
</target>
</generator>
</configuration>
<executions>
<execution>
<id>generate-jooq-sources</id>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<database>
<type>MYSQL</type>
<containerImage>mysql:8.0</containerImage> <!-- optional -->
<username>root</username> <!-- Use root because of permissions --><!-- optional -->
<password>${db.password}</password> <!-- optional -->
<databaseName>${db.schema}</databaseName> <!-- optional -->
</database>
<flyway>
<!-- https://github.com/steve-community/steve/issues/157 -->
<initSql>SET default_storage_engine=InnoDB;</initSql>
<!-- we need this because of extensions. they have a higher version number
namespace reserved (e.g. 8.x.x). new migrations in core version should
be executed in the extended version as well -->
<outOfOrder>true</outOfOrder>

<!-- Because maven produces this warning after upgrading from 4.2.0 to 5.1.0:
[WARNING] Could not find schema history table `stevedb`.`flyway_schema_history`, but found
`stevedb`.`schema_version` instead. You are seeing this message because Flyway changed its
default for flyway.table in version 5.0.0 to flyway_schema_history and you are still relying
on the old default (schema_version). Set flyway.table=schema_version in your configuration to
fix this. This fallback mechanism will be removed in Flyway 6.0.0. -->
<table>schema_version</table>

<cleanDisabled>true</cleanDisabled>
<driver>${db.driver}</driver>
<locations>
filesystem:src/main/resources/db/migration
</locations>
</flyway>
<!-- http://www.jooq.org/doc/3.5/manual/code-generation/codegen-configuration/
http://www.jooq.org/doc/3.5/manual/code-generation/codegen-advanced/ -->
<jooq>
<jdbc>
<driver>${db.driver}</driver>
</jdbc>

<generator>
<database>
<name>org.jooq.meta.mysql.MySQLDatabase</name>
<includes>.*</includes>
<excludes>flyway_schema_history</excludes>
<inputSchema>${db.schema}</inputSchema>
<unsignedTypes>false</unsignedTypes>

<forcedTypes>
<forcedType>
<name>BOOLEAN</name>
<!-- https://github.com/jOOQ/jOOQ/issues/7719 -->
<includeTypes>(?i:(TINY|SMALL|MEDIUM|BIG)?INT(UNSIGNED)?\(1\))</includeTypes>
</forcedType>
<forcedType>
<name>BOOLEAN</name>
<includeExpression>.*\.OCPP_TAG_ACTIVITY\.(IN_TRANSACTION|BLOCKED)</includeExpression>
</forcedType>
<forcedType>
<userType>org.joda.time.DateTime</userType>
<converter>de.rwth.idsg.steve.utils.DateTimeConverter</converter>
<includeExpression>.*</includeExpression>
<includeTypes>.*(TIMESTAMP|DATETIME).*</includeTypes>
</forcedType>
<forcedType>
<userType>org.joda.time.LocalDate</userType>
<converter>de.rwth.idsg.steve.utils.DateConverter</converter>
<includeExpression>.*\.BIRTH_DAY</includeExpression>
<includeTypes>.*(DATE).*</includeTypes>
</forcedType>
</forcedTypes>
</database>
<generate>
<fluentSetters>true</fluentSetters>
<!-- https://www.jooq.org/doc/3.14/manual/code-generation/codegen-advanced/codegen-config-generate/codegen-generate-java-time-types/
JOOQ switching to java.time data types messes up our converters since we use JodaTime.
Until we as a project completely switch to java.time, I am disabling it. -->
<javaTimeTypes>false</javaTimeTypes>
</generate>

<target>
<packageName>jooq.steve.db</packageName>
<directory>${project.build.directory}/generated-sources</directory>
</target>
</generator>
</jooq>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down

0 comments on commit 8b8e2ec

Please sign in to comment.