org.flywaydb.core.api.configuration.FluentConfiguration Java Examples

The following examples show how to use org.flywaydb.core.api.configuration.FluentConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImportDataConfiguration.java    From sbp with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnProperty(prefix = "spring.flyway", name = "import-data")
@DependsOn("flywayInitializer")
public FlywayDataImporter flywayDataImporter() {
    FluentConfiguration flywayConf = plugin != null
            ? Flyway.configure(plugin.getWrapper().getPluginClassLoader()) : Flyway.configure();
    flywayConf.configuration(flyway.getConfiguration());
    flywayConf.baselineVersion("0");
    flywayConf.baselineOnMigrate(true);
    flywayConf.locations("classpath:/db_data");
    flywayConf.table("_db_data");
    Flyway importDataFlyway = new Flyway(flywayConf);
    FlywayDataImporter importer = new FlywayDataImporter(importDataFlyway);
    importer.setOrder(Ordered.LOWEST_PRECEDENCE);
    return importer;
}
 
Example #2
Source File: CleanSchemaConfiguration.java    From sbp with Apache License 2.0 6 votes vote down vote up
@Override
public void migrate(Flyway flyway) {
    try (Statement stat = flyway.getConfiguration().getDataSource().getConnection().createStatement()) {
        for (String schema : flyway.getConfiguration().getSchemas()) {
            stat.execute("DROP SCHEMA IF EXISTS "+schema + " CASCADE");
        }
    } catch (SQLException e) {
        throw new RuntimeException(e.getMessage(), e);
    }

    if (plugin != null) {
        FluentConfiguration alterConf = Flyway.configure(plugin.getWrapper().getPluginClassLoader());
        alterConf.configuration(flyway.getConfiguration());
        new Flyway(alterConf).migrate();
    } else {
        flyway.migrate();
    }
}
 
Example #3
Source File: AbstractFlywayMigration.java    From micronaut-flyway with Apache License 2.0 6 votes vote down vote up
/**
 * Configure the Flyway runner for a specific configuration and a dataSource.
 *
 * @param config     The {@link FlywayConfigurationProperties}
 * @param dataSource The {@link DataSource}
 */
void run(FlywayConfigurationProperties config, DataSource dataSource) {
    if (config.isEnabled()) {
        FluentConfiguration fluentConfiguration = config.getFluentConfiguration();
        fluentConfiguration.dataSource(dataSource);

        Flyway flyway = fluentConfiguration.load();
        this.applicationContext.registerSingleton(Flyway.class, flyway, Qualifiers.byName(config.getNameQualifier()), false);

        if (config.isAsync()) {
            runAsync(config, flyway);
        } else {
            runFlyway(config, flyway);
        }
    }
}
 
Example #4
Source File: SkipperFlywayConfigurationCustomizer.java    From spring-cloud-skipper with Apache License 2.0 6 votes vote down vote up
@Override
public void customize(FluentConfiguration configuration) {
	// boot's flyway auto-config doesn't allow to define callbacks per
	// vendor id, so essentially customizing those here.
	DataSource dataSource = configuration.getDataSource();
	DatabaseDriver databaseDriver = getDatabaseDriver(dataSource);
	logger.info("Customizing flyway config, detected DatabaseDriver as {}.", databaseDriver);
	if (databaseDriver == DatabaseDriver.POSTGRESQL) {
		configuration.callbacks(new PostgresBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.MYSQL || databaseDriver == DatabaseDriver.MARIADB) {
		configuration.callbacks(new MysqlBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.SQLSERVER) {
		configuration.callbacks(new MsSqlBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.ORACLE) {
		configuration.callbacks(new OracleBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.DB2) {
		configuration.callbacks(new Db2BeforeBaseline());
	}
}
 
Example #5
Source File: CustomFlywayConfiguration.java    From nifi-registry with Apache License 2.0 6 votes vote down vote up
@Override
public void customize(final FluentConfiguration configuration) {
    final DatabaseType databaseType = getDatabaseType(configuration.getDataSource());
    LOGGER.info("Determined database type is {}", new Object[] {databaseType.name()});

    switch (databaseType) {
        case MYSQL:
            LOGGER.info("Setting migration locations to {}", new Object[] {LOCATIONS_MYSQL});
            configuration.locations(LOCATIONS_MYSQL);
            break;
        case POSTGRESQL:
            LOGGER.info("Setting migration locations to {}", new Object[] {LOCATIONS_POSTGRES});
            configuration.locations(LOCATIONS_POSTGRES);
            break;
        default:
            LOGGER.info("Setting migration locations to {}", new Object[] {LOCATIONS_DEFAULT});
            configuration.locations(LOCATIONS_DEFAULT);
            break;
    }
}
 
Example #6
Source File: FlywayConfiguration.java    From cerberus with Apache License 2.0 6 votes vote down vote up
@Autowired
public FlywayConfiguration(
    DataSource dataSource,
    @Value("${flyway.schemas}") String flywaySchemas,
    @Value("${flyway.locations}") String flywayLocations) {

  FluentConfiguration conf =
      new FluentConfiguration()
          .dataSource(dataSource)
          .schemas(flywaySchemas)
          .table(
              "schema_version") // For some reason in guice land this is not flyway_schema_history
          .locations(flywayLocations.split(";"));

  Flyway flyway = new Flyway(conf);
  flyway.migrate();
}
 
Example #7
Source File: DataFlowFlywayConfigurationCustomizer.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Override
public void customize(FluentConfiguration configuration) {
	// boot's flyway auto-config doesn't allow to define callbacks per
	// vendor id, so essentially customizing those here.
	DataSource dataSource = configuration.getDataSource();
	DatabaseDriver databaseDriver = getDatabaseDriver(dataSource);
	if (databaseDriver == DatabaseDriver.POSTGRESQL) {
		configuration.callbacks(new PostgresBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.MYSQL || databaseDriver == DatabaseDriver.MARIADB) {
		configuration.callbacks(new MysqlBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.SQLSERVER) {
		configuration.callbacks(new MsSqlBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.ORACLE) {
		configuration.callbacks(new OracleBeforeBaseline());
	}
	else if (databaseDriver == DatabaseDriver.DB2) {
		configuration.callbacks(new Db2BeforeBaseline());
	}
}
 
Example #8
Source File: FlywayClassLoaderConfiguration.java    From sbp with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public FlywayMigrationStrategy migrationStrategy() {
    return flyway -> {
        FluentConfiguration alterConf = Flyway.configure(plugin.getWrapper().getPluginClassLoader());
        alterConf.configuration(flyway.getConfiguration());
        new Flyway(alterConf).migrate();
    };
}
 
Example #9
Source File: FlywayExtensionConfigFixture.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public void assertDefaultConfigurationSettings(Configuration configuration) {
    FluentConfiguration defaultConfiguration = Flyway.configure();
    assertEquals(locations(configuration), locations(defaultConfiguration));
    assertEquals(sqlMigrationPrefix(configuration), sqlMigrationPrefix(defaultConfiguration));
    assertEquals(repeatableSqlMigrationPrefix(configuration), repeatableSqlMigrationPrefix(defaultConfiguration));
    assertEquals(tableName(configuration), tableName(defaultConfiguration));
    assertEquals(schemaNames(configuration), schemaNames(defaultConfiguration));

    assertEquals(connectRetries(configuration), connectRetries(defaultConfiguration));

    assertEquals(baselineOnMigrate(configuration), baselineOnMigrate(defaultConfiguration));
    assertEquals(baselineVersion(configuration), baselineVersion(defaultConfiguration));
    assertEquals(baselineDescription(configuration), baselineDescription(defaultConfiguration));
}
 
Example #10
Source File: FlywayCreator.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public Flyway createFlyway(DataSource dataSource) {
    FluentConfiguration configure = Flyway.configure();
    configure.dataSource(dataSource);
    if (flywayRuntimeConfig.connectRetries.isPresent()) {
        configure.connectRetries(flywayRuntimeConfig.connectRetries.getAsInt());
    }
    if (flywayRuntimeConfig.schemas.isPresent()) {
        configure.schemas(flywayRuntimeConfig.schemas.get().toArray(EMPTY_ARRAY));
    }
    if (flywayRuntimeConfig.table.isPresent()) {
        configure.table(flywayRuntimeConfig.table.get());
    }
    configure.locations(flywayBuildTimeConfig.locations.toArray(EMPTY_ARRAY));
    if (flywayRuntimeConfig.sqlMigrationPrefix.isPresent()) {
        configure.sqlMigrationPrefix(flywayRuntimeConfig.sqlMigrationPrefix.get());
    }
    if (flywayRuntimeConfig.repeatableSqlMigrationPrefix.isPresent()) {
        configure.repeatableSqlMigrationPrefix(flywayRuntimeConfig.repeatableSqlMigrationPrefix.get());
    }
    configure.baselineOnMigrate(flywayRuntimeConfig.baselineOnMigrate);
    configure.validateOnMigrate(flywayRuntimeConfig.validateOnMigrate);
    configure.outOfOrder(flywayRuntimeConfig.outOfOrder);
    if (flywayRuntimeConfig.baselineVersion.isPresent()) {
        configure.baselineVersion(flywayRuntimeConfig.baselineVersion.get());
    }
    if (flywayRuntimeConfig.baselineDescription.isPresent()) {
        configure.baselineDescription(flywayRuntimeConfig.baselineDescription.get());
    }
    configure.placeholders(flywayRuntimeConfig.placeholders);
    return configure.load();
}
 
Example #11
Source File: PersistenceTestConfig.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Bean("flyway")
public Flyway flyway() {
	
	FluentConfiguration configuration = Flyway.configure()
	.dataSource("jdbc:h2:nio:./db/h2.db", "", "")
	.locations("db/migration/h2", "db/migration/common")
	.validateOnMigrate(true)
	.outOfOrder(false);
	
	return new Flyway(configuration);
}
 
Example #12
Source File: FlywayTestExecutionListener.java    From flyway-test-extensions with Apache License 2.0 5 votes vote down vote up
/**
 * Handling of the change of locations configuration of a flyway.
 *
 * @param annotation
 *            current annotation
 * @param flyWay
 *            bean
 * @param executionInfo
 *            current test context.
 */
private void locationsMigrationHandling(final FlywayTest annotation,
                                        final Flyway flyWay, final String executionInfo) {
    final String[] locations = annotation.locationsForMigrate();

    // now migration handling for locations support
    String[] oldLocations = convertLocationToString(flyWay);
    boolean override = annotation.overrideLocations();
    try {
        String[] useLocations = null;
        if (override) {

            useLocations = locations;
        } else {
            // Fill the locations
            useLocations = Arrays.copyOf(oldLocations, oldLocations.length
                    + locations.length);

            System.arraycopy(locations, 0, useLocations, oldLocations.length, locations.length);
        }
        if (logger.isDebugEnabled()) {
            logger.debug(String
                    .format("******** Start migration from locations directories '%s'  for  '%s'.",
                            Arrays.asList(useLocations), executionInfo));

        }

        FluentConfiguration fluentConfiguration = new FluentConfiguration();
        fluentConfiguration.configuration(flyWay.getConfiguration())
        .locations(useLocations)
        .load()
        .migrate();
    } finally {
        // reset the flyway bean to original configuration.
        //flyWay.setLocations(oldLocations);
    }
}
 
Example #13
Source File: FlywayConfigurationProperties.java    From micronaut-flyway with Apache License 2.0 4 votes vote down vote up
/**
 * @return The flyway configuration builder
 */
public FluentConfiguration getFluentConfiguration() {
    return fluentConfiguration;
}
 
Example #14
Source File: FlywayFactory.java    From dropwizard-flyway with Apache License 2.0 4 votes vote down vote up
private FluentConfiguration createConfiguration() {
    final String[] emptyStringArray = new String[0];
    FluentConfiguration flyway = classLoader == null ? Flyway.configure() : Flyway.configure(classLoader);
    flyway = flyway
          .baselineOnMigrate(baselineOnMigrate)
          .baselineVersion(baseLineVersion)
          .callbacks(callbacks.toArray(emptyStringArray))
          .cleanDisabled(cleanDisabled)
          .cleanOnValidationError(cleanOnValidationError)
          .encoding(encoding)
          .group(group)
          .ignoreFutureMigrations(ignoreFutureMigrations)
          .ignoreIgnoredMigrations(ignoreIgnoredMigrations)
          .ignoreMissingMigrations(ignoreMissingMigrations)
          .installedBy(installedBy)
          .locations(locations.toArray(emptyStringArray))
          .mixed(mixed)
          .outOfOrder(outOfOrder)
          .placeholderPrefix(placeholderPrefix)
          .placeholderReplacement(placeholderReplacement)
          .placeholderSuffix(placeholderSuffix)
          .placeholders(placeholders)
          .resolvers(resolvers.toArray(emptyStringArray))
          .initSql(initSql)
          .schemas(schemas.toArray(emptyStringArray))
          .skipDefaultCallbacks(skipDefaultCallbacks)
          .skipDefaultResolvers(skipDefaultResolvers)
          .sqlMigrationPrefix(sqlMigrationPrefix)
          .sqlMigrationSeparator(sqlMigrationSeparator)
          .sqlMigrationSuffixes(sqlMigrationSuffixes.toArray(emptyStringArray))
          .table(metaDataTableName)
          .validateOnMigrate(validateOnMigrate);

    if (defaultSchema != null) {
        flyway.defaultSchema(defaultSchema);
    }

    // Commercial features
    if (batch != null) {
        flyway.batch(batch);
    }
    if (dryRunOutputFile != null) {
        flyway.dryRunOutput(dryRunOutputFile);
    }
    if (errorOverrides != null) {
        flyway.errorOverrides(errorOverrides.toArray(emptyStringArray));
    }
    if (oracleSqlPlus != null) {
        flyway.oracleSqlplus(oracleSqlPlus);
    }
    if (stream != null) {
        flyway.stream(stream);
    }
    if (target != null) {
        flyway.target(target);
    }
    if (undoSqlMigrationPrefix != null) {
        flyway.undoSqlMigrationPrefix(undoSqlMigrationPrefix);
    }

    return flyway;
}