Search in sources :

Example 1 with MigrateResult

use of org.flywaydb.core.api.output.MigrateResult in project openremote by openremote.

the class PersistenceService method prepareSchema.

protected void prepareSchema(String connectionUrl, String databaseUsername, String databasePassword, String schemaName) {
    LOG.fine("Preparing database schema");
    List<String> locations = new ArrayList<>();
    List<String> schemas = new ArrayList<>();
    schemas.add(schemaName);
    appendSchemas(schemas);
    appendSchemaLocations(locations);
    flyway = Flyway.configure().dataSource(connectionUrl, databaseUsername, databasePassword).schemas(schemas.toArray(new String[0])).locations(locations.toArray(new String[0])).baselineOnMigrate(true).load();
    MigrationInfo currentMigration = flyway.info().current();
    if (currentMigration == null && !forceClean) {
        LOG.warning("DB is empty so changing forceClean to true");
        forceClean = true;
    }
    if (forceClean) {
        LOG.warning("!!! Cleaning database !!!");
        flyway.clean();
    } else {
        LOG.fine("Not cleaning, using existing database");
    }
    for (MigrationInfo i : flyway.info().pending()) {
        LOG.info("Pending task: " + i.getVersion() + ", " + i.getDescription() + ", " + i.getScript());
    }
    MigrateResult result = flyway.migrate();
    LOG.info("Applied database schema migrations: " + result.migrationsExecuted);
    flyway.validate();
}
Also used : MigrationInfo(org.flywaydb.core.api.MigrationInfo) MigrateResult(org.flywaydb.core.api.output.MigrateResult)

Aggregations

MigrationInfo (org.flywaydb.core.api.MigrationInfo)1 MigrateResult (org.flywaydb.core.api.output.MigrateResult)1