Implement Complex Migrations in Java: Jdbcmigration V - Description - Java
Implement Complex Migrations in Java: Jdbcmigration V - Description - Java
@Override
public void migrate(Connection connection) throws
Exception {
// implement your migration here …
}
}
beforeMigrate
beforeEachMigrate
www.thoughts-on-java.org
Java-based Migrations and Callbacks in Flyway
afterEachMigrate
afterMigrate
beforeClean
afterClean
beforeInfo
afterInfo
beforeValidate
afterValidate
beforeBaseline
afterBaseline
beforeRepair
afterRepair
SQL Callbacks
The implementation of an SQL callback is straightforward. You just
need to add an SQL script, with the name of the lifecycle trigger you
want to use, to your migration directory. The migration directory is
either the sql folder of the Flyway command line client or the
src/main/resources/db/migration folder of your Java application.
So, if you want to execute a SQL script after Flyway migrated your
database, you just need to put all SQL statements into a file with the
name afterMigrate.sql and copy it to the sql or
src/main/resources/db/migration folder.
Java Callbacks
If your callback operation is too complex for an SQL script, you can
also implement it in Java. That requires 2 steps. You need a class that
implements the FlywayCallback interface and register it in your
Flyway instance.
If you need access to the Flyway configuration, you should also
implement the ConfigurationAware interface. It defines a method
which Flyway will call with the configuration object so that you can
store it in an internal property and use it in your callback
implementation.
www.thoughts-on-java.org
Java-based Migrations and Callbacks in Flyway
Another class you should know is the BaseFlywayCallback class. It
implements the FlywayCallback and the ConfigurationAware
interface and provides empty implementations for all methods.
So, you just need to override the callback methods you want to
implement, like in the following class which only provides an
implementation for the afterMigrate lifecycle callback.
www.thoughts-on-java.org