Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flyway repair with Spring Boot

I don't quite understand what I am supposed to do when a migration fails using Flyway in a Spring Boot project.

I activated Flyway by simply adding the Flyway dependency in my pom.xml. And everything works fine. My database scripts are migrated when I launch the Spring Boot app.

But I had an error in one of my scripts and my last migration failed. Now when I try to migrate, there is a "Migration checksum mismatch". Normally, I would run mvn flyway:repair, but since I am using Spring Boot, I am not supposed to use the Flyway Maven plug-in. So what am I supposed to do?

like image 907
Jean-François Beauchef Avatar asked May 26 '16 13:05

Jean-François Beauchef


People also ask

How do you implement a Flyway in a spring boot?

Configuring Flyway Database gradle file. In application properties, we need to configure the database properties for creating a DataSource and also flyway properties we need to configure in application properties. For properties file users, add the below properties in the application. properties file.

What is Flyway used for in spring boot?

Spring Boot integrates with Flyway, one of the most extensively used database migration tools, to make database migrations easier. Flyway is a tool that allows you to version control incremental changes to your database such that you can easily and completely migrate to a new version.


1 Answers

there are several ways to perform a repair on the database. I personally prefer the simple SQL statement.

SQL Statement:

Just delete the row with the failed migration. After that you can run the migration again.

Run flyway directly

You can install Flyway local and run flyway repair in the console

Use the Flyway Maven Plugin

Add the Flyway Maven Plugin to your pom and run mvn flyway:repair. I don't think this contradict with the Spring Boot concept.

Extend Spring Boot

Spring Boot will call Flyway.migrate() to perform the database migration. If you would like more control, provide a @Bean that implements FlywayMigrationStrategy.

In the FlywayMigrationStrategy you can call the migrate or repair method from flyway. More Information is available in the Spring Boot Reference Guide.

I don't think the FlywayMigrationStrategy in the application is the right place to repair the database. A failed migration is a exception and should be handle outside the application.

like image 68
Daniel Käfer Avatar answered Sep 24 '22 08:09

Daniel Käfer