Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set databasename, username and password #1

Closed
simasch opened this issue May 10, 2023 · 8 comments
Closed

How to set databasename, username and password #1

simasch opened this issue May 10, 2023 · 8 comments

Comments

@simasch
Copy link

simasch commented May 10, 2023

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

How can I do that?

@simasch simasch changed the title Set databasename, username and password How to set databasename, username and password May 10, 2023
@LouizFC
Copy link

LouizFC commented May 10, 2023

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)

@romchellis
Copy link
Contributor

Would be cool also add other Flyway and jooq specific properties

@sivaprasadreddy
Copy link
Contributor

@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
Copy link
Author

simasch commented May 16, 2023

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

@sivaprasadreddy
Copy link
Contributor

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
Copy link
Author

simasch commented May 16, 2023

Brilliant! Works as expected. Than you very much.

@sivaprasadreddy
Copy link
Contributor

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
Copy link
Author

simasch commented May 16, 2023

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

@simasch simasch closed this as completed May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants