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

Improve usability of SQL init scripts with reusable containers #2127

Closed
aguibert opened this issue Dec 1, 2019 · 8 comments
Closed

Improve usability of SQL init scripts with reusable containers #2127

aguibert opened this issue Dec 1, 2019 · 8 comments
Labels

Comments

@aguibert
Copy link
Contributor

aguibert commented Dec 1, 2019

Background

Recently reusable container support was added to Testcontainers, which allows significant time savings during local dev/test cycles. However, there is room for improvement in the usability of reusable containers and init scripts (specifically JdbcDatabaseContainer init scripts).

Currently the JdbcDatabaseContainer class has the following method:

    public SELF withInitScript(String initScriptPath) {
        this.initScriptPath = initScriptPath;
        return self();
    }

This allows an initialization SQL script to be run after the container is started. Typically to populate some test data in the database.

Problem

When combining this mechanism with reusable containers, the init script still runs every time the tests start, even though the same DB instance is being reused. This can cause problems if the init script was not written to account for a DB instance being reused. For example, it may try to create a table that already exists from the previous run, or it may try to insert some data that is already present in the DB from the previous run.

Proposed solution

Add an overloaded method to JdbcDatabaseContainer that allows the user to specify whether or not their init script should be run when attaching to a reused container. For example:

/**
 * Runs a SQL initialization script after this container is started
 * @param initScriptPath Path to the initialization script
 * @param runOnReuse True if the initialization script should run again on a container that has already been started and is being reused. False otherwise.
 */
public SELF withInitScript(String initScriptPath, boolean runOnReuse) {
 // ...
}
@aguibert aguibert mentioned this issue Dec 1, 2019
2 tasks
@aguibert aguibert changed the title Improve usability of init scripts with reusable containers Improve usability of SQL init scripts with reusable containers Dec 1, 2019
@stale
Copy link

stale bot commented Feb 29, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.

@stale stale bot added the stale label Feb 29, 2020
@aritzbastida
Copy link

any news on this?

@stale stale bot removed the stale label Feb 29, 2020
@stale
Copy link

stale bot commented May 30, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe this is a mistake, please reply to this comment to keep it open. If there isn't one already, a PR to fix or at least reproduce the problem in a test case will always help us get back on track to tackle this.

@stale stale bot added the stale label May 30, 2020
@stale
Copy link

stale bot commented Jun 13, 2020

This issue has been automatically closed due to inactivity. We apologise if this is still an active problem for you, and would ask you to re-open the issue if this is the case.

@stale stale bot closed this as completed Jun 13, 2020
@ganapathi004
Copy link

@aguibert Is this feature on the roadmap or is it being implemented in some other way?

@aguibert
Copy link
Contributor Author

not sure, I wanted to get feedback from maintainers before I spent the time to implement such a feature.

@bsideup do you have thoughts on this proposal?

@hungbang
Copy link

Any update on this topic? I am facing same problem when using reuse feature

@kiview
Copy link
Member

kiview commented Oct 18, 2022

Work on this is currently not planned, while reuse is an experimental feature. I'd suggest using other production-grade mechanisms (e.g. Flyway, Liquibase) to set up your database schema/data instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants