Flyway: Using both custom and Java Callbacks

437 views Asked by At

If I specify

flyway.callbacks=com.myclass.CustomCallBack

it gets called fine, but I notice it seems to suppress the SQL callback functionality. Is there any way to have both? I notice there's a SqlScriptFlywayCallback, but that's one of your 'internal' classes....

2

There are 2 answers

0
Axel Fontaine On BEST ANSWER

Currently the only way is to refer both to the internal class and your own. Please file an enhancement request in the issue tracker.

0
Mirko Rossini On

As a simple workaround, you can initialize the SqlScriptFlywayCallback as Axel suggested. Here's how I did it, given an initialized instance of flyway:

 DbSupport dbSupport;
 try {
     dbSupport = DbSupportFactory.createDbSupport(flyway.getDataSource().getConnection(), false);
 } catch (SQLException e) {
     throw new RuntimeException("Could not get connection to database");
 }  

 final FlywayCallback runSqlCallbacks = new SqlScriptFlywayCallback(
         dbSupport,
         flyway.getClassLoader(),
         new Locations(flyway.getLocations()),
         new PlaceholderReplacer(flyway.getPlaceholders(),
                 flyway.getPlaceholderPrefix(),
                 flyway.getPlaceholderSuffix()),
         flyway.getEncoding(),
         flyway.getSqlMigrationSuffix()
 ); 

 flyway.setCallbacks(
         runSqlCallbacks,
         new MyCallback(...));