1

Comments that contain # which are perfectly valid in mysql 5.7 according to: https://dev.mysql.com/doc/refman/5.7/en/comments.html seem to break the init file for a mysql docker test container. When I initialize a datasource in the application-test.properties file as:

spring.datasource.jdbcUrl=jdbc:tc:mysql:5.7:///test?TC_INITSCRIPT=file:src/test/resources/test-init.sql

Any comment like this in the test-init.sql file will cause mysql to ignore the rest of the file when the comment is structured like this:

# Dump of table USERS
# ------------------------------------------------------------

However, when the comment is like this:

/*
# Dump of table USERS
# ------------------------------------------------------------
*/

The rest of the file executes successfully.

Also, test containers does not throw a mysql error. Instead, it tells me my tables do not exist when I try to reference them in my application code.

I also am using test containers instead of H2 because I want it to support the exact mysql syntax. Does anyone have a hint at how I can correct this? I normally export schema from an existing database using sequel pro's export.

Atreya
  • 43
  • 5
  • 1
    I think it's a bug. From a quick look it ends up running the script with https://github.com/testcontainers/testcontainers-java/blob/d69602467983709d8bdc5665c83f3a0502a189c3/modules/database-commons/src/main/java/org/testcontainers/ext/ScriptUtils.java#L313 which has only 1 default comment prefix which is `--`. Can you please raise an issue in https://github.com/testcontainers/testcontainers-java, thank you! – Oleg Šelajev Nov 03 '21 at 20:38
  • But also as a general consideration, ScriptUtils is very capable but still only can do so much to support all the dialects and all the syntax features. So for complex scripts please consider using a proper schema migration tool. But I still think we should raise an issue here for visibility. – Oleg Šelajev Nov 03 '21 at 20:42

0 Answers0