testcontainers / testcontainers-jooq-codegen-maven-plugin

jOOQ code generator using Testcontainers
Apache License 2.0
56 stars 9 forks source link

How to set databasename, username and password #1

Closed simasch closed 1 year ago

simasch commented 1 year ago

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

How can I do that?

LouizFC commented 1 year ago

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: https://github.com/testcontainers/testcontainers-java/issues/1454)

romchellis commented 1 year ago

Would be cool also add other Flyway and jooq specific properties

sivaprasadreddy commented 1 year ago

@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?

simasch commented 1 year ago

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

sivaprasadreddy commented 1 year ago

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?

simasch commented 1 year ago

Brilliant! Works as expected. Than you very much.

sivaprasadreddy commented 1 year ago

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>
simasch commented 1 year ago

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