-
I have an initial script like this. DO $$ BEGIN
CREATE TYPE post_status AS ENUM( 'DRAFT', 'PENDING_MODERATION', 'PUBLISHED');
EXCEPTION
WHEN duplicate_object THEN null;
END $$; It worked well when using But when I create a Postgres docker container using testcontainers like this. var container = new PostgreSQLContainer("postgres:12")
.withInitScript("init.sql"); It will fail with the following exception. Caused by: org.postgresql.util.PSQLException: Unterminated dollar quote started at position 3 in SQL DO $$ BEGIN CREATE TYPE post_status AS ENUM( 'DRAFT', 'PENDING_MODERATION', 'PUBLISHED'). Expected terminating $$ The example project to reproduce this issue: https://github.com/hantsy/spring6-sandbox/blob/master/jdbc/src/test/java/com/example/demo/testcontainers/PostRepositoryTestWithTestcontainers.java |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @hantsy, this is related to this issue: The best solution is to delegate the script execution to Postgres itself. This can be achieved by copying the file into a special location in the container (a feature of the Postgres image): new PostgreSQLContainer("postgres:12")
.withCopyFileToContainer(
MountableFile.forClasspathResource("init.sql"),
"/docker-entrypoint-initdb.d/init.sql"
); |
Beta Was this translation helpful? Give feedback.
Hey @hantsy, this is related to this issue:
#4441
The best solution is to delegate the script execution to Postgres itself. This can be achieved by copying the file into a special location in the container (a feature of the Postgres image):