Skip to content

Datasource Devservice: Skip init script, if testcontainers.reuse.enable=true #36987

Open

Description

Describe the bug

When testcontainers.reuse.enable=true, the database container is reused between Quarkus hot reloads (a really awesome feature btw). But also the init script referenced in quarkus.datasource.devservices.init-script-path seems to be executed again.

I would count that as a bug - but that might be debateable.

My reasoning is: The script is meant to initialize the database. So if I keep the database up, it does not need to be initialized again. If your init script does contain actions that are not repeatable, there will be errors on hot reload and your app has to be restarted manually (and sometimes the still running container needs to be killed manually).

If not counted as bug, it should at least be configurable. Maybe some kinds of init scripts should run on each hot reload and some don't?

Current workaround is to make your init scripts idempotent (which is often easy, but in case of creating users in postgres a simple "if not exists" is not available for example).

Expected behavior

Don't execute the init script on quarkus hot reload, when testcontainers.reuse.enable=true is set.

Actual behavior

Script gets executed again on every hot reload.

How to Reproduce?

Steps to reproduce:

  1. Create a Quarkus Project with SQL Datasource, for example with "quarkus-jdbc-postgresql" dependency
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-jdbc-postgresql</artifactId>
    </dependency>
  1. Configure DevService with init script and enable container reuse

application.properties:

quarkus.datasource.devservices.init-script-path=db/init/init-users.sql

~/.testcontainers.properties:

testcontainers.reuse.enable=true

  1. Do something non-idempotent in the init script, that will produce an error on second execution, for example:

src/main/resources/db/init/init-users.sql:
create user app_user with password 'local';

  1. Start the app (everything should be fine for first start)
  2. Change a line in your code and trigger something for the hot reload feature (for example a rest api call)

=> Now your init script will throw an error

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions