quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.73k stars 2.67k forks source link

Devservice init-script with volumes fails on 2nd start #38080

Closed georgleber closed 9 months ago

georgleber commented 9 months ago

Describe the bug

I have setup my quarkus dev environment using PostgreSQL DB devservice. I have defined quarkus.datasource.devservices.init-script-path with an initial SQL script, that is executed correctly. But when defining quarkus.datasource.devservices.volumes I would expect that the init script is only run once on the first run and after that (volumes exist) it skips initialization.

But on the second start, Quarkus fails starting up, because the data that should be setup in the init-script already exists.

Expected behavior

Quarkus should recognize if there is already data and skip the init-script execution.

Actual behavior

On second start Quarkus fials, because the data that should be imported by the init-script already exists.

How to Reproduce?

I have created a small reproducer. After second start, the error shows up. https://github.com/georgleber/quarkus-initscript-volumes-problem

Output of uname -a or ver

Darwin MBPro 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:55:06 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6020 arm64

Output of java -version

OpenJDK Temurin-17.0.9

Quarkus version or git rev

3.6.4

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

Apache Maven 3.9.6

quarkus-bot[bot] commented 9 months ago

/cc @geoand (devservices), @stuartwdouglas (devservices)

gastaldi commented 9 months ago

Quarkus should recognize if there is already data and skip the init-script execution.

I think that's unlikely to happen. Your init-script should be prepared to succeed if the data you're attempting to create already exists (using an IF EXISTS)

geoand commented 9 months ago

I think that's unlikely to happen. Your init-script should be prepared to succeed if the data you're attempting to create already exists (using an IF EXISTS)

šŸ‘šŸ¼

georgleber commented 9 months ago

Ok, found it a little unintuitive. I was used to spin up e.g. Postgres with initscript, which is run just once initially. So my expectation was, that Quarkus would handle it similarly.

I have changed my script to only import if data does not exist, thanks for the hint. (BTW @gastaldi IF EXISTS does only work for creating structure but unfortunately not for inserting data)