Need to setup a profile which gets Flyway to clean the database on re-start

Viewed 245

I want to start with a clean database when I run my spring boot application with a profile used for integration tests. The application is running in its own JVM and the integration tests are running in another JVM. It appears that adding:

spring.flyway.clean-disabled=false

to the integration properties file should do the trick, but it does not work. The documentation says that the default setting for spring.flyway.clean-disabled is false, which implies if I don't set spring.flyway.clean-disabled in any of my properties files, then every time I start my application, I should get an empty database. But that is not true. The contents of the database are persisted between starts of the application. So what needs to be done to start the application with a clean database? I'm using Spring Boot 2.3.1.RELEASE.

1 Answers

The documentation says that the default setting for spring.flyway.clean-disabled is false, which implies if I don't set spring.flyway.clean-disabled in any of my properties files, then every time I start my application, I should get an empty database.

No, you shouldn't get an empty database every time you start your application. Flyway is a database-migration tool. It would be rather awkward if it would by default completely wipe your database on every application start.

In contrast to the migrate command (which is automatically invoked by Spring Boot on application startup), clean is a command that is helpful mainly during development and testing. You have to explicitly invoke it (for example via Maven / Gradle).

The cleanDisabled parameter is just a safeguard that can be configured to prevent the clean command from being executed in a production environment.

Related