Flyway 4.0 java base callback afterValidate do not catch the hook

I have SQL and Java based migration. I'm trying to use the Flyway callback hook to do something else right after checking, but it doesn’t catch this callback. From the documentation, it looks 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 answer:

 public class FruitShopFlywayCallback extends BaseFlywayCallback { @Override public void afterValidate(Connection dataConnection) { System.out.println("it worksssssssss"); } } 

My thought was that as soon as the migration was complete, flyway was about to make a callback in this method. I was not sure what I was missing?

+6
source share
2 answers

I just needed to register a callback when initializing the flyway. Here is what I did. Thereafter. 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); 
+3
source

In case it will be useful. I was looking for how to configure Flyway to work with Java callbacks using Maven. You need to register your callback classes with Flyway (using Flyway with pure Java, you must use setCallbacks).

In maven, it looks something like this:

 <plugin> <groupId>org.flywaydb</groupId> <artifactId>flyway-maven-plugin</artifactId> <version>${flyway.version}</version> <configuration> <driver>org.hsqldb.jdbcDriver</driver> <url>jdbc:hsqldb:file:${project.build.directory}/db/flyway_sample;shutdown=true</url> <user>SA</user> <callbacks> <callback>example.MyCallback</callback> </callbacks> </configuration> </plugin> 
+3
source

All Articles