Łukasz Rzeszotarski
Łukasz Rzeszotarski

Reputation: 6140

Spring Boot 3 + Flyway + Postgres 9.5

We are currently upgrading our Spring Boot based application to version 3 but the following issue occurs:

  1. Spring Boot 3 uses Flyway in version 9.
  2. We need to support our database which is Postgres 9.5, but Flyway Community in version 9 does not have support for Postgres 9.5.

Is there any way to use Spring Boot 3 + Flyway Community + Postgres that is not supported by Flyway Community (in our case 9.5)?

Upvotes: 0

Views: 4533

Answers (1)

Henning
Henning

Reputation: 3899

Spring Boot 3 will only auto-configure Flyway if it is at least version 8 or higher. You can use Spring Boot 3 with older Flyway versions if you disable the auto-configuration and do the configuration yourself.

There are multiple ways to disable the auto-configuration of Flyway:

  • You can pass FlywayAutoConfiguration.class to the field exclude of the annotation @SpringBootApplication (or @EnableAutoConfiguration),
  • you can set the property spring.flyway.enabled to false, or
  • you can expose a bean of type Flyway such that the auto-configuration backs off.

If the auto-configuration of Spring Boot 2 worked fine for you, then I'd recommend the last approach. You can take the code of FlywayAutoConfiguration from Spring Boot 2, remove the stuff that's specific for auto-configuration classes (e.g. every annotation whose name starts with Conditional), and put it in your own code as a normal configuration class annotated with @Configuration. This class will then expose at least a bean of type Flyway to let the auto-configuration back off and a bean of type FlywayMigrationInitializer that performs the actual migrations.

Upvotes: 3

Related Questions