Home > Net >  How to remove prefix from Flyway migration name?
How to remove prefix from Flyway migration name?

Time:10-02

By default, Flyway searches for migrations that start with "V" in the folder db/migration, for example: V1_1_0__init_schema.sql

However, my migrations have the following naming pattern (and I can't change my migrations name): 20210902193819451__init_schema.sql

How can I remove the letter "V" from the default behavior of Flyway, so that my migrations can be found?

I've already tried to set the following property in my configurations file: spring.flyway.sql-migration-prefix: "", but that doesn't work, and I get the following error:

Invocation of init method failed; nested exception is org.flywaydb.core.api.exception.FlywayValidateException: Validate failed: Migrations have failed validation

CodePudding user response:

In this case, Flyway is a Spring managed bean. Your configuration should be spring.flyway.sql-migration-prefix=V as described here.

Caution, as database migrations are meant to have different prefixes for versioning, undo, and repeatable migrations. You should also note that entity validation might come from Flyway (from table flyway_schema_history), which checks from your script's checksum, and Hibernate, which checks from your @Entity model.

CodePudding user response:

I've solved the problem adding the following configs to my application.yml file:

spring.flyway.sql-migration-prefix: "20"
spring.flyway.sql-migration-separator: "_"

Instead of removing the prefix, I've simply replaced it, so Flyway successfully found and run the files.

  • Related