Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flyway 4.0 java base callback afterValidate not catching the hook

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?

like image 911
AirWick219 Avatar asked Apr 21 '16 21:04

AirWick219


Video Answer


1 Answers

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);
like image 57
AirWick219 Avatar answered Oct 28 '22 02:10

AirWick219