Reputation: 30995
I've been using flyway to handle my sql scripts migrations and am very happy with it. However, when I decided to move forward with spring boot and flyway I have stuck when I tried to run the different flyway commands from the app.
When I run my fat jar app, the migrate
flyway command is automatically executed. All went well until one of the scripts failed in a linux (because of the case sensitive). So, when I wanted to execute the repair
command I had no way to do it, so I had to manually remove the entry in the schema_version
table.
So, my question is that if it is even possible to other flyway commands through the app without creating a custom flyway handler and just using its native integration.
I didn't find any spring boot property for command
or something like this.
Any help?
Upvotes: 2
Views: 4254
Reputation: 9625
There's no command
property for Flyway integration. If you want you can implement your own FlywayMigrationStrategy
, which is a one method interface:
public interface FlywayMigrationStrategy {
/**
* Trigger flyway migration.
* @param flyway the flyway instance
*/
void migrate(Flyway flyway);
}
You can pick up for instance a command line argument that you pass and do repair
instead of migrate
:
void migrate(Flyway flyway) {
String command = env.getProperty("flyway.commamd", "migrate");
switch (command) {
case "migrate":
flyway.migrate();
break;
case "repair":
flyway.repair();
break;
default:
throw new IllegalArgumentException("Invalid command: " + command);
}
}
Check the docs here.
Upvotes: 3