I have both SQL and Java based migrations. I am trying to use the Flyway callback hook to do something else right after the validation is done, but it is not catching this callback. From the documentation, it seems like it's as simple as the following.
Here is my file structure:
-java
--db
---migrations
----V1__apple <----java based
--FruitShopFlywayCallback.java <---- Callback class
-resources
--migrations
--- V1__orange.sql <----sql based
My callback:
public class FruitShopFlywayCallback extends BaseFlywayCallback {
@Override
public void afterValidate(Connection dataConnection) {
System.out.println("it worksssssssss");
}
}
My thought was that once the migration is done, flyway was going to callback into this method. I was not sure what am I missing?
I just needed to register the call back when initializing flyway. Here is what i did. After that. it works as expected
// Initializing Flyway
Flyway flyway = new Flyway();
flyway.setDataSource(dataSource);
flyway.setValidateOnMigrate(true);
// Register call back.
FruitShopFlywayCallback callback = new FruitShopFlywayCallback();
flyway.setCallbacks(callback);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With