Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Startup failure due to non-empty schema when using Flyway and Spring Integration's DataSource initialization #28079

Closed
agebhar1 opened this issue Sep 21, 2021 · 2 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@agebhar1
Copy link
Contributor

A simple test

@SpringBootTest
class ApplicationTests {

    @Test
    void contextLoads() {
    }

}

fails if Spring Integration JDBC, Flyway and an embedded database is used since Spring Boot v2.5.3 with:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is org.flywaydb.core.api.FlywayException: Found non-empty schema(s) "PUBLIC" but no schema history table. Use baseline() or set baselineOnMigrate to true to initialize the schema history table.

A minimal failing example can be found here https://github.com/agebhar1/spring-boot-flyway-si-jdbc and the details for running tests here https://github.com/agebhar1/spring-boot-flyway-si-jdbc/actions/runs/1258717007.

The problem is that with embedded database tests IntegrationJdbcConfiguration with IntegrationDataSourceInitializer (from Spring Boot autoconfiguration) runs after Flyway in Spring Boot v2.5.1 and since Spring Boot v2.5.3 before Flyway hence the database is not empty and Flyway fails.

I suggest to add @AutoConfigureAfter(FlywayAutoConfiguration.class) to IntegrationJdbcConfiguration. And check this also for Liquibase.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 21, 2021
@wilkinsona wilkinsona changed the title Spring Boot since 2.5.3 fails simple @SpringBootTest w/ Flyway and Spring Integration JDBC Startup failure when using Flyway and Spring Integration's DataSource initialization Sep 22, 2021
@wilkinsona wilkinsona changed the title Startup failure when using Flyway and Spring Integration's DataSource initialization Startup failure due to non-empty schema when using Flyway and Spring Integration's DataSource initialization Sep 22, 2021
@wilkinsona wilkinsona added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 22, 2021
@wilkinsona wilkinsona added this to the 2.5.5 milestone Sep 22, 2021
@wilkinsona
Copy link
Member

This is due to the changes made in 433f3d6 for #27215. The problem is that the new AbstractDataSourceInitializerDatabaseInitializerDetector is unordered so the initializers that it detects end up running before Flyway (and Liquibase). The problem doesn't occur in 2.6 due to the changes made for #27206.

@agebhar1
Copy link
Contributor Author

Thanks @wilkinsona for the background details.

@wilkinsona wilkinsona self-assigned this Sep 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

3 participants