Search in sources :

Example 1 with SchemaInitializationException

use of org.eclipse.che.core.db.schema.SchemaInitializationException in project che by eclipse.

the class FlywaySchemaInitializer method init.

@Override
public void init() throws SchemaInitializationException {
    try (final Connection conn = dataSource.getConnection()) {
        final Flyway flyway = new Flyway();
        flyway.setDataSource(dataSource);
        flyway.setLocations(locations);
        flyway.setClassLoader(Thread.currentThread().getContextClassLoader());
        final DbSupport dbSupport = DbSupportFactory.createDbSupport(conn, true);
        final String productName = conn.getMetaData().getDatabaseProductName().toLowerCase();
        flyway.setResolvers(new CustomSqlMigrationResolver(productName, dbSupport, placeholderReplacer));
        flyway.setSkipDefaultResolvers(true);
        flyway.setBaselineOnMigrate(baselineOnMigrate);
        if (baselineOnMigrate) {
            flyway.setBaselineVersionAsString(baselineVersion);
        }
        flyway.setSqlMigrationSeparator(versionSeparator);
        flyway.setSqlMigrationSuffix(scriptsSuffix);
        flyway.setSqlMigrationPrefix(scriptsPrefix);
        flyway.migrate();
    } catch (SQLException | RuntimeException x) {
        throw new SchemaInitializationException(x.getLocalizedMessage(), x);
    }
}
Also used : Flyway(org.flywaydb.core.Flyway) SQLException(java.sql.SQLException) Connection(java.sql.Connection) DbSupport(org.flywaydb.core.internal.dbsupport.DbSupport) SchemaInitializationException(org.eclipse.che.core.db.schema.SchemaInitializationException)

Aggregations

Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 SchemaInitializationException (org.eclipse.che.core.db.schema.SchemaInitializationException)1 Flyway (org.flywaydb.core.Flyway)1 DbSupport (org.flywaydb.core.internal.dbsupport.DbSupport)1