https://github.com/testcontainers/testcontainers-jooq-codegen-maven-plugin
jOOQ code generator using Testcontainers
https://github.com/testcontainers/testcontainers-jooq-codegen-maven-plugin
Last synced: 3 months ago
JSON representation
jOOQ code generator using Testcontainers
- Host: GitHub
- URL: https://github.com/testcontainers/testcontainers-jooq-codegen-maven-plugin
- Owner: testcontainers
- License: apache-2.0
- Created: 2023-05-06T11:43:13.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-06T21:13:09.000Z (about 1 year ago)
- Last Synced: 2024-05-22T18:20:55.639Z (about 1 year ago)
- Language: Java
- Size: 165 KB
- Stars: 45
- Watchers: 10
- Forks: 10
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# testcontainers-jooq-codegen-maven-plugin
The `testcontainers-jooq-codegen-maven-plugin` simplifies the jOOQ code generation
by using [Testcontainers](https://www.testcontainers.org/) and applying database migrations.[](https://github.com/testcontainers/testcontainers-jooq-codegen-maven-plugin/actions/workflows/build.yml)
## Summary
- Plugin migration and code generation might be skipped using `skip` property
- If you need to reuse existing database connection - take a look at [Jooq section](#Jooq)## Database Configuration
To configure a target database, you need to specify at least database `type` property.
#### Properties
| Parameter | Required | Default value | Description |
|----------------|----------|----------------------------------------------------------------------------|----------------------------------------------------------------|
| type | yes | | Database implementation one of: `POSTGRES` `MYSQL` `MARIADB` |
| containerImage | | Provided from database type,usually latest version from official container | Image of used container if not default picked |
| username | | Provided from database container if not specified | Database username for container |
| password | | Provided from database container if not specified | Database password for container |
| databaseName | | Provided from database container if not specified | Database name for container |#### `database` block configuration
```xml
POSTGRES
postgres:15-alpine
test
test
test```
## Migration tools:
### Flyway
Flyway works the same way as the original plugin
Please find original documentation by link https://flywaydb.org/documentation/usage/maven/#### Configuration
At runtime default configuration files will be autoloaded as it documented -
https://flywaydb.org/documentation/configuration/configfile
Currently, the plugin supports all properties existing in Flyway
You can find them by original link
https://flywaydb.org/documentation/configuration/parameters/
Now [config files parameter](https://flywaydb.org/documentation/configuration/parameters/configFiles) is not
implemented yet, but you can use config file at default location ${baseDir}/flyway.conf#### `flyway` block configuration
- Zero configuration with defaults
```xml
```
- Adding properties
```xml
bank
true
my_custom_history_table
filesystem:src/main/resources/db/migration/postgres,
filesystem:src/main/resources/db/migration/postgresql
```
### Liquibase
Liquibase's configuration works the same way as the original maven plugin, with some limitations
Please find documentation by
link https://docs.liquibase.com/tools-integrations/maven/using-liquibase-and-maven-pom-file.html#### Properties
Now supports only the most useful properties
| Property | type | default |
|--------------------------------|--------|------------------------------------------------------------------------------------------------------------------------------|
| changeLogPath | String | if changeLogDirectory is provided - db.changelog-root.xml, otherwise - src/main/resources/db/changelog/db.changelog-root.xml |
| changeLogDirectory | String | projectBaseDir |
| parameters | Map | |
| defaultSchemaName | String | |
| liquibaseSchemaName | String | |
| databaseChangeLogTableName | String | |
| databaseChangeLogLockTableName | String | |Reference to Liquibase properties - https://docs.liquibase.com/concepts/connections/creating-config-properties.html
#### `liquibase` block configuration
- Zero configuration with defaults
```xml
```
- Adding properties
```xml
db.changelog-root.yml
src/main/resources/db/postgres/changelog
custom
```### JOOQ
#### Properties
`generator` - property to configure JOOQ code generation settings.
See https://www.jooq.org/doc/latest/manual/code-generation/codegen-configuration for all the supporting configuration
properties.
`configurationFiles` / `configurationFile` - are not implemented yet
`jdbc` - If it has all the necessary JDBC parameters (URL, name, password), it will use the existing database, and no container will be spun up.
`baseDir` - directory relative to which generated sources will be generated , `{project.basedir}` - default#### `jooq` block configuration
```xml
...
....
```
#### Plugin dependencies configuration
```xml
org.postgresql
postgresql
${postgresql.version}```
## Examples
### Complete example
Example with `PostgreSQL` and minimal configuration with `Flyway` and `JOOQ`
```xml
org.testcontainers
testcontainers-jooq-codegen-maven-plugin
${testcontainers-jooq-codegen-maven-plugin.version}
org.testcontainers
postgresql
${testcontainers.version}
org.postgresql
postgresql
${postgresql.version}
generate-jooq-sources
generate
generate-sources
POSTGRES
.*
public
org.jooq.codegen.maven.example
target/generated-sources/jooq
```
### More examples
[MariaDB + Flyway](examples/mariadb-flyway-example )
[MySQL + Flyway](examples/mysql-flyway-example )
[Postgres + Flyway](examples/postgres-flyway-example )
[Postgres + Liquibase](examples/postgres-liquibase-example )### Try with example application
```shell
$ cd examples/postgres-flyway-example
$ mvn clean package
```The JOOQ code should be generated under example/target/generated-sources/jooq folder.
## CREDITS:
This plugin is heavily based on official https://github.com/jOOQ/jOOQ/tree/main/jOOQ-codegen-maven.