Ensure that Flyway/Liquibase run before jOOQ's DSLContext is used
See gh-25279
This commit is contained in:
committed by
Andy Wilkinson
parent
08802d3afa
commit
c55200d19a
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,11 +32,15 @@ import org.flywaydb.core.api.callback.Event;
|
||||
import org.flywaydb.core.api.migration.JavaMigration;
|
||||
import org.flywaydb.core.internal.license.FlywayProUpgradeRequiredException;
|
||||
import org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.impl.DefaultDSLContext;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
@@ -520,6 +524,25 @@ class FlywayAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void userConfigurationDslContextDependency() {
|
||||
this.contextRunner
|
||||
.withUserConfiguration(EmbeddedDataSourceConfiguration.class, CustomFlywayWithJooqConfiguration.class)
|
||||
.run((context) -> {
|
||||
BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("dslContext");
|
||||
assertThat(beanDefinition.getDependsOn()).containsExactly("flyway");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void userConfigurationWithFlywayMigrationAndDslContextDependency() {
|
||||
this.contextRunner.withUserConfiguration(EmbeddedDataSourceConfiguration.class,
|
||||
CustomFlywayMigrationInitializerWithJooqConfiguration.class).run((context) -> {
|
||||
BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("dslContext");
|
||||
assertThat(beanDefinition.getDependsOn()).containsExactly("flywayMigrationInitializer", "flyway");
|
||||
});
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
static class FlywayDataSourceConfiguration {
|
||||
|
||||
@@ -748,6 +771,42 @@ class FlywayAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
static class CustomFlywayWithJooqConfiguration {
|
||||
|
||||
@Bean
|
||||
Flyway flyway(DataSource dataSource) {
|
||||
return Flyway.configure().dataSource(dataSource).load();
|
||||
}
|
||||
|
||||
@Bean
|
||||
DSLContext dslContext() {
|
||||
return new DefaultDSLContext(SQLDialect.H2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
protected static class CustomFlywayMigrationInitializerWithJooqConfiguration {
|
||||
|
||||
private final DataSource dataSource;
|
||||
|
||||
protected CustomFlywayMigrationInitializerWithJooqConfiguration(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FlywayMigrationInitializer flywayMigrationInitializer(Flyway flyway) {
|
||||
return new FlywayMigrationInitializer(flyway);
|
||||
}
|
||||
|
||||
@Bean
|
||||
DSLContext dslContext() {
|
||||
return new DefaultDSLContext(SQLDialect.H2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final class CustomClassLoader extends ClassLoader {
|
||||
|
||||
private CustomClassLoader(ClassLoader parent) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,6 +41,7 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jooq.JooqAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.boot.context.event.ApplicationStartingEvent;
|
||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
@@ -374,6 +375,16 @@ class LiquibaseAutoConfigurationTests {
|
||||
.run(assertLiquibase((liquibase) -> assertThat(liquibase.getTag()).isEqualTo("1.0.0")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void userConfigurationDslContextDependency() {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class))
|
||||
.withUserConfiguration(LiquibaseUserConfiguration.class, EmbeddedDataSourceConfiguration.class)
|
||||
.run((context) -> {
|
||||
BeanDefinition beanDefinition = context.getBeanFactory().getBeanDefinition("dslContext");
|
||||
assertThat(beanDefinition.getDependsOn()).containsExactly("springLiquibase");
|
||||
});
|
||||
}
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertLiquibase(Consumer<SpringLiquibase> consumer) {
|
||||
return (context) -> {
|
||||
assertThat(context).hasSingleBean(SpringLiquibase.class);
|
||||
|
||||
Reference in New Issue
Block a user