Flyway 7.5.1 及更高版本无法初始化 Zonky-test DB
Posted
技术标签:
【中文标题】Flyway 7.5.1 及更高版本无法初始化 Zonky-test DB【英文标题】:Flyway version 7.5.1 and up can not initialize Zonky-test DB 【发布时间】:2021-05-07 11:06:19 【问题描述】:使用 Flyway 版本 7.5.0
,它仍然可以正常工作。但是版本7.5.1
和7.5.2
会产生以下错误:
[...]
java.lang.IllegalStateException: Unexpected error occurred while initializing the data source
at com.google.common.base.Preconditions.checkState(Preconditions.java:459)
at io.zonky.test.db.flyway.DefaultFlywayDataSourceContext.getTarget(DefaultFlywayDataSourceContext.java:89)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:195)
at com.sun.proxy.$Proxy65.getConnection(Unknown Source)
at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:59)
at org.flywaydb.core.internal.jdbc.JdbcConnectionFactory.<init>(JdbcConnectionFactory.java:69)
at org.flywaydb.core.Flyway.execute(Flyway.java:507)
at org.flywaydb.core.Flyway.migrate(Flyway.java:165)
at org.springframework.boot.autoconfigure.flyway.FlywayMigrationInitializer.afterPropertiesSet(FlywayMigrationInitializer.java:66)
[...]
任何想法,有什么问题或如何解决?
下面是我重现问题的最小示例的代码:
Dockerfile
FROM openjdk:11.0.10-jdk AS base
# Needed for embedded PostgreSQL-server to start during integration tests.
# see: https://github.com/zonkyio/embedded-database-spring-test
RUN groupadd --system --gid 1000 test
RUN useradd --system --gid test --uid 1000 --shell /bin/bash --create-home test
USER test
WORKDIR /home/test
ADD . /home/test/
RUN ./gradlew test
build.gradle
buildscript
ext
kotlinVersion = '1.4.21'
springBootVersion = '2.4.2'
repositories
mavenCentral()
dependencies
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("org.jetbrains.kotlin:kotlin-allopen:$kotlinVersion")
classpath("org.jetbrains.kotlin:kotlin-noarg:$kotlinVersion")
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'kotlin-jpa'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.acme'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
compileKotlin
kotlinOptions
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
compileTestKotlin
kotlinOptions
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
repositories
mavenCentral()
dependencies
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: "$springBootVersion"
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.18'
implementation group: 'org.flywaydb', name: 'flyway-core', version: '7.5.2'
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: "$kotlinVersion"
testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: "$springBootVersion"
testImplementation group: 'junit', name: 'junit', version: '4.13.1'
testImplementation group: 'io.zonky.test', name: 'embedded-database-spring-test', version: '1.6.2'
test
testLogging
exceptionFormat = 'full'
compileKotlin.dependsOn(processResources)
compileJava.dependsOn(processResources)
settings.gradle
rootProject.name = 'flywayzonkytest'
src/main/kotlin/com/acme/flywayzonkytest/Application.kt
package com.acme.flywayzonkytest
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@SpringBootApplication
class Application
fun main(args: Array<String>)
runApplication<Application>(*args)
src/main/resources/application.yml
spring:
flyway:
enabled: true
src/main/resources/db/migration/V1__thing.sql
CREATE TABLE thing (
some_id BIGINT PRIMARY KEY NOT NULL,
some_name VARCHAR NOT NULL
);
src/test/kotlin/com/acme/flywayzonkytest/integration/CreateContextTest.kt
package com.acme.flywayzonkytest.integration
import io.zonky.test.db.AutoConfigureEmbeddedDatabase
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner
@RunWith(SpringRunner::class)
@AutoConfigureEmbeddedDatabase
@SpringBootTest
class CreateContextTest
@Test
fun `test create context`()
【问题讨论】:
我在zonkyio/embedded-database-spring-test
中打开了一个问题:github.com/zonkyio/embedded-database-spring-test/issues/149
【参考方案1】:
Flyway 在版本 7.5.0
和 7.5.1
之间进行了一些重大更改。 zonkyio/embedded-database-spring-test
的维护者在他的库中只是 implemented a fix/workaround,它包含在版本 1.6.3
中。 :-)
【讨论】:
以上是关于Flyway 7.5.1 及更高版本无法初始化 Zonky-test DB的主要内容,如果未能解决你的问题,请参考以下文章
使用 jquery 1.6 及更高版本会使 Django 的 FilteredSelectMutliple 无法使用
离子推送通知自定义声音无法在 Android Oreo 及更高版本上播放
Google 应用程序目录 API(1.6 及更高版本)DotNetOpenAuth 无法解析