use of com.helger.phoss.smp.backend.sql.migration.V5__MigrateTransportProfilesToDB in project phoss-smp by phax.
the class FlywayMigrator method runFlyway.
void runFlyway(@Nonnull final EDatabaseType eDBType) {
ValueEnforcer.notNull(eDBType, "DBType");
LOGGER.info("Starting to run Flyway for DB type " + eDBType);
final ConfigFile aCF = SMPServerConfiguration.getConfigFile();
final Callback aCallbackLogging = new BaseCallback() {
public void handle(@Nonnull final Event aEvent, @Nonnull final Context aContext) {
if (LOGGER.isInfoEnabled())
LOGGER.info("Flyway: Event " + aEvent.getId());
if (aEvent == Event.AFTER_EACH_MIGRATE && aContext != null) {
final MigrationInfo aMI = aContext.getMigrationInfo();
if (aMI instanceof MigrationInfoImpl) {
final ResolvedMigration aRM = ((MigrationInfoImpl) aMI).getResolvedMigration();
if (aRM != null)
if (LOGGER.isInfoEnabled())
LOGGER.info(" Performed migration: " + aRM);
}
}
}
};
final Callback aCallbackAudit = new BaseCallback() {
public void handle(@Nonnull final Event aEvent, @Nonnull final Context aContext) {
if (aEvent == Event.AFTER_EACH_MIGRATE && aContext != null) {
final MigrationInfo aMI = aContext.getMigrationInfo();
if (aMI instanceof MigrationInfoImpl) {
final ResolvedMigration aRM = ((MigrationInfoImpl) aMI).getResolvedMigration();
// before that version
if (aRM != null && aRM.getVersion().isAtLeast("7"))
AuditHelper.onAuditExecuteSuccess("sql-migration-success", aRM.getVersion().toString(), aRM.getDescription(), aRM.getScript(), aRM.getType().name(), aRM.getPhysicalLocation());
}
}
}
};
final FluentConfiguration aConfig = Flyway.configure().dataSource(new DriverDataSource(FlywayMigrator.class.getClassLoader(), aCF.getAsString(SMPJDBCConfiguration.CONFIG_JDBC_DRIVER), aCF.getAsString(SMPJDBCConfiguration.CONFIG_JDBC_URL), aCF.getAsString(SMPJDBCConfiguration.CONFIG_JDBC_USER), aCF.getAsString(SMPJDBCConfiguration.CONFIG_JDBC_PASSWORD))).baselineOnMigrate(true).validateOnMigrate(false).baselineVersion("1").baselineDescription("SMP 5.2.x database layout, MySQL only").locations("db/migrate-" + eDBType.getID()).javaMigrations(new V2__MigrateDBUsersToPhotonUsers(), new V5__MigrateTransportProfilesToDB(), new V10__MigrateRolesToDB(), new V11__MigrateUsersToDB(), new V12__MigrateUserGroupsToDB(), new V14__MigrateSettingsToDB(), new V15__MigrateDBUsersToPhotonUsers()).callbacks(aCallbackLogging, aCallbackAudit);
// Flyway to handle the DB schema?
final String sSchema = aCF.getAsString(SMPJDBCConfiguration.CONFIG_JDBC_SCHEMA);
if (StringHelper.hasText(sSchema)) {
// Use the schema only, if it is explicitly configured
// The default schema name is ["$user", public] and as such unusable
aConfig.schemas(sSchema);
}
// If no schema is specified, schema create should also be disabled
final boolean bCreateSchema = aCF.getAsBoolean(SMPJDBCConfiguration.CONFIG_JDBC_SCHEMA_CREATE, false);
aConfig.createSchemas(bCreateSchema);
final Flyway aFlyway = aConfig.load();
if (false)
aFlyway.validate();
aFlyway.migrate();
LOGGER.info("Finished running Flyway");
}
Aggregations