Home > Back-end >  Spring Boot Flyway Testcontainers(mariaDB): Table "xxxx" doesn't exist
Spring Boot Flyway Testcontainers(mariaDB): Table "xxxx" doesn't exist

Time:05-17

I use Testcontainers with mariaDB database in a Spring Boot project for unit testing. I recently upgraded Spring Boot from 2.4.4 to 2.6.6 and found out that the unit test started to fail. The Testcontainers was created again (?) after the Flyway migration happened (which created the database schema).

I am slightly confused and wonder whether there are specific configuration that needs to be set to make the unit test work again.

Dependencies are as below

plugins {
    ...
    id 'org.springframework.boot' version '2.6.6'
    id "org.flywaydb.flyway" version "8.4.2"
    ...
}

dependencies {
    ...
    testCompileOnly 'junit:junit:4.13.2'
    testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.8.2'
    implementation  "org.flywaydb:flyway-core:8.1.0"
    implementation 'org.mariadb.jdbc:mariadb-java-client:3.0.4'
    implementation "org.jooq:jooq:3.16.5"
    testImplementation "org.testcontainers:mariadb:1.16.2"
    ....

Configuration is as below

spring.datasource.url=jdbc:tc:mariadb:10.5:///
spring.datasource.driver-class-name=org.testcontainers.jdbc.ContainerDatabaseDriver
spring.datasource.username=""
spring.datasource.password=""

spring.jooq.sql-dialect=MARIADB

spring.flyway.enabled=true
spring.flyway.locations=filesystem:./src/main/resources/db/migration
spring.flyway.url=jdbc:tc:mariadb:10.5:///
spring.flyway.baseline-on-migrate=true

# logging
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type=TRACE

Log message is as below

INFO 49309 --- [    Test worker] c.a.a.m.r.MyUnitTest   : Starting MyUnitTest using Java 11.0.11 on xxxxxxx with PID 49309 (started by user.name in /Volumes/code/sample/sample)
INFO 49309 --- [    Test worker] c.a.a.m.r.MyUnitTest   : The following 1 profile is active: "test"
INFO 49309 --- [    Test worker] trationDelegate$BeanPostProcessorChecker : Bean 'io.opentracing.contrib.spring.cloud.async.DefaultAsyncAutoConfiguration' of type [io.opentracing.contrib.spring.cloud.async.DefaultAsyncAutoConfiguration$$EnhancerBySpringCGLIB$$3e8860ae] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
WARN 49309 --- [    Test worker] i.o.c.s.t.c.TracerAutoConfiguration      : Tracer bean is not configured! Switching to NoopTracer
INFO 49309 --- [    Test worker] o.c.s.w.s.ServerTracingAutoConfiguration : Creating WebMvcConfigurer bean with class io.opentracing.contrib.spring.web.interceptor.TracingHandlerInterceptor
INFO 49309 --- [    Test worker] o.t.utility.ImageNameSubstitutor         : Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
INFO 49309 --- [    Test worker] o.t.d.DockerClientProviderStrategy       : Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
INFO 49309 --- [    Test worker] o.t.d.DockerClientProviderStrategy       : Found Docker environment with local Unix socket (unix:///var/run/docker.sock)
INFO 49309 --- [    Test worker] org.testcontainers.DockerClientFactory   : Docker host IP address is localhost
INFO 49309 --- [    Test worker] org.testcontainers.DockerClientFactory   : Connected to docker: 
  Server Version: 20.10.13
  API Version: 1.41
  Operating System: Docker Desktop
  Total Memory: 7859 MB
INFO 49309 --- [    Test worker] o.t.utility.RegistryAuthLocator          : Credential helper/store (docker-credential-desktop) does not have credentials for index.docker.io
2022-05-16 09:18:36.309  INFO 49309 --- [    Test worker] o.t.utility.RyukResourceReaper           : Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
INFO 49309 --- [    Test worker] org.testcontainers.DockerClientFactory   : Checking the system...
INFO 49309 --- [    Test worker] org.testcontainers.DockerClientFactory   : ✔︎ Docker server version should be at least 1.6.0
INFO 49309 --- [    Test worker] org.testcontainers.DockerClientFactory   : ✔︎ Docker environment should have more than 2GB free disk space
INFO 49309 --- [    Test worker]            
  • Related