you should use flyway Callbacks like:
https://flywaydb.org/documentation/concepts/callbacks#beforeEachMigrate
https://flywaydb.org/documentation/concepts/callbacks#beforeEachMigrate
see also :
https://flywaydb.org/documentation/tutorials/callbacks.html
SQL Callbacks
The most convenient way to hook into Flyway’s lifecycle is through SQL callbacks. These are simply sql files in the configured locations following a certain naming convention: the event name followed by the SQL migration suffix.
Using the default settings, Flyway looks in its default locations (<install_dir>/sql) for the Command-line tool) for SQL files like beforeMigrate.sql, beforeEachMigrate.sql, afterEachMigrate.sql, …
Placeholder replacement works just like it does for SQL migrations.
Optionally the callback may also include a description. In that case the callback name is composed of the event name, the separator, the description and the suffix. Example: beforeRepair__vacuum.sql.
Note: Flyway will also honor any sqlMigrationSuffixes you have configured, when scanning for SQL callbacks.
Java Callbacks
If SQL Callbacks aren’t flexible enough for you, you have the option to implement the Callback interface yourself. You can even hook multiple Callback implementations in the lifecycle. Java callbacks have the additional flexibility that a single Callback implementation can handle multiple lifecycle events, and are therefore not bound by the SQL callback