testcontainers/testcontainers-jooq-codegen-maven-plugin

How to set databasename, username and password

simasch opened this issue · 8 comments

I need to set databasename, username and password for the PostgreSQL container.

How can I do that?

I also need to specify database/schema name for a MariaDB container. I took a look at the plugin code:
https://github.com/sivalabs/jooq-testcontainers-codegen-maven-plugin/blob/db5a79a4dcbae3773dc77baed5f012dfdebe9d03/src/main/java/com/sivalabs/jooq/codegen/Plugin.java#L77-L91
So tried specifying a <jdbc> block in the plugin configuration, which it seemed to initially work, but I runned in some classpath issues (which was the main reason for me using this plugin, for reference: testcontainers/testcontainers-java#1454)

Would be cool also add other Flyway and jooq specific properties

@simasch
In this plugin, a database instance is spinning up using Testcontainers using the default schema, credentials and use those credentials for running Flyway migrations and JOOQ code generation. So, there is no need to configure schema, credentials.

What is your usecase? Are you trying to connect to any existing database by providing credentials?

I have SQL scripts run by Flyway that need a specific schema or user.

Hi @simasch
Just added support to specify username, password, databaseName using which the database instance will be created by Testcontainers.

As this plugin is not yet published under testcontainers org, could you please install the plugin and test it locally to verify your usecasse?

Steps:

1. Install plugin locally

$ git clone https://github.com/testcontainers/jooq-testcontainers-codegen-maven-plugin.git
$ ./mvnw clean install

2. Specify username, password, databaseName in plugin configuration <database> section

<plugin>
                <groupId>org.testcontainers</groupId>
                <artifactId>jooq-testcontainers-codegen-maven-plugin</artifactId>
                <version>${jooq-testcontainers-codegen-maven-plugin.version}</version>
                <dependencies>
                    <dependency>
                        <groupId>org.testcontainers</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>${testcontainers.version}</version>
                    </dependency>
                    <dependency>
                        <groupId>org.postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>${postgres.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <id>generate-jooq-sources</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <database>
                                <type>POSTGRES</type>
                                <containerImage>postgres:15.2-alpine</containerImage>
                                <username>test</username> <!-- optional -->
                                <password>test</password> <!-- optional -->
                                <databaseName>test</databaseName> <!-- optional -->
                            </database>
                            <flyway>
                                <locations>
                                    filesystem:src/main/resources/db/migration/postgres
                                </locations>
                            </flyway>
                            <generator>
                                <database>
                                    <includes>.*</includes>
                                    <excludes>flyway_schema_history</excludes>
                                    <inputSchema>public</inputSchema>
                                </database>
                                <target>
                                    <packageName>org.jooq.codegen.maven.example</packageName>
                                    <directory>target/generated-sources/jooq</directory>
                                </target>
                            </generator>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Please try it and let me know whether your usecase is covered with this support or not?

Brilliant! Works as expected. Than you very much.

Published the plugin under testcontianners org. See https://central.sonatype.com/artifact/org.testcontainers/jooq-testcontainers-codegen-maven-plugin/0.0.1

@simasch Please verify with new maven co-ordinates and if working fine then we can close this issue.

<dependency>
    <groupId>org.testcontainers</groupId>
    <artifactId>jooq-testcontainers-codegen-maven-plugin</artifactId>
    <version>0.0.1</version>
</dependency>

Works! Right on time for my workshop and my talk at Spring I/O!
thank you @sivaprasadreddy