1 | initial version |
To integrate a Quarkus bean into a Flyway-based Java migration, follow these steps:
Here's an example of a Quarkus bean that performs a migration task:
import javax.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class MyMigrationBean {
public void migrate() {
// perform migration task here
}
}
To use this bean in a Flyway migration script, create a script file (e.g. V1_mymigration.sql) with the following contents:
-- Migration script using Quarkus bean
-- Invoke the migrate() method of MyMigrationBean
CREATE OR REPLACE FUNCTION migrate_my_data ()
RETURNS void AS $$
BEGIN
perform migrate();
END;
$$ LANGUAGE plpgsql;
SELECT migrate_my_data();
This script creates a PL/pgSQL function that invokes the migrate() method of the Quarkus bean and executes it. The script can then be executed through Flyway to apply the migration changes to the target database:
mvn flyway:migrate
Or alternatively:
./gradlew flywayMigrate