Reputation: 944
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?
Upvotes: 7
Views: 884
Reputation: 944
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);
Upvotes: 4
Reputation: 11540
In case this is helpful. 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 would use setCallbacks).
In maven this 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>
Upvotes: 3