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

Feature: Support for TC_INITSCRIPT parameter #26

Open
ferdinand-swoboda opened this issue Jul 28, 2023 · 4 comments
Open

Feature: Support for TC_INITSCRIPT parameter #26

ferdinand-swoboda opened this issue Jul 28, 2023 · 4 comments

Comments

@ferdinand-swoboda
Copy link

Hey, thanks for this plugin, it's a neat quality of life & code improvement!

While trying to bring this goodie to an internal project I noticed that the JDBC connection parameter TC_INITSCRIPT (and TC_INITFUNCTION) are not mentioned / covered by the configuration options.
I'm specifically referring to the case when one does not wish to connect to a pre-existing container and thus does not provide a <jooq><jdbc>...</jdbc></jooq> block.

Did I simply miss this in the documentation?
If not, could this be supported with relative ease?

Possibly naively speaking, I would add this as a nested configuration option e.g.

<database>
    <type>POSTGRES</type>
    <init_script>/../../docker/postgres/01_site.sql</init_script>
</database>

Happy to look into creating a PR

@romchellis
Copy link
Contributor

Please feel free for pull request

@ferdinand-swoboda
Copy link
Author

My use case turned out to be covered by the existing DB user credentials options.
I think it's better to wait for more interest in this feature before increasing the API surface.
Up to you wether you want to leave the issue open for that purpose.

zzzLobster added a commit to zzzLobster/testcontainers-jooq-codegen-maven-plugin that referenced this issue Oct 9, 2023
@zzzLobster
Copy link
Contributor

zzzLobster commented Feb 24, 2024

@eddumelendez

Currently, the suggested approach is using copy files instead due to most of the images provides a fresh initialization folder.

Could you please clarify what 'copy file' means?
Is it about using 'Initialization scripts' of a DB container?
Like this for PG:

If you would like to do additional initialization in an image derived from this one, add one or more *.sql, *.sql.gz, or *.sh scripts under /docker-entrypoint-initdb.d (creating the directory if necessary).

MySQL and MariaDB:

Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d

If I understand the proposal correctly, the plugin should accept list of files and copy them into the init folder of the container.
Is that correct assumption?

Config could look like

        <copy>
          <entries>
            <entry>
              <sourceFile>filesystem:${project.basedir}/src/test/resources/db/init.sql</sourceFile>
              <containerPath>/docker-entrypoint-initdb.d/</containerPath>
            </entry>
            <entry>
              <sourceFile>classpath:db/postgres/init.sh</sourceFile>
              <containerPath>/docker-entrypoint-initdb.d/123.sh</containerPath>
            </entry>
          </entries>
        </copy>

Current approach in the PR just mimics initScript mechanism built into JdbcDatabaseContainer of Testcontainers.

@kiview
Copy link
Member

kiview commented Apr 25, 2024

@eddumelendez was referring to using the Copy API. I think your config proposal makes sense @zzzLobster 👍

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