Java Code Examples for org.flywaydb.core.Flyway#configure()
The following examples show how to use
org.flywaydb.core.Flyway#configure() .
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 |
@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 |
@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: FlywayMigrationServletContextListener.java From thorntail with Apache License 2.0 | 6 votes |
@Override public void contextInitialized(ServletContextEvent sce) { ServletContext sc = sce.getServletContext(); Flyway flyway = new Flyway(); String dataSourceJndi = sc.getInitParameter(FLYWAY_JNDI_DATASOURCE); if (dataSourceJndi != null) { try { DataSource dataSource = (DataSource) new InitialContext().lookup(dataSourceJndi); flyway.setDataSource(dataSource); } catch (NamingException ex) { logger.log(Level.SEVERE, "Error while looking up DataSource", ex); // Do not proceed return; } } else { String url = sc.getInitParameter(FLYWAY_JDBC_URL); String user = sc.getInitParameter(FLYWAY_JDBC_USER); String password = sc.getInitParameter(FLYWAY_JDBC_PASSWORD); flyway.setDataSource(url, user, password); } // Configure with flyway.* system properties flyway.configure(System.getProperties()); flyway.migrate(); }
Example 4
Source File: DataSourceConfiguration.java From alf.io with GNU General Public License v3.0 | 6 votes |
@Bean public Flyway migrator(DataSource dataSource) { var configuration = Flyway.configure(); var jdbcTemplate = new JdbcTemplate(dataSource); var matches = jdbcTemplate.queryForObject("select count(*) from information_schema.tables where table_name = 'schema_version'", Integer.class); var tableName = matches != null && matches > 0 ? "schema_version" : configuration.getTable(); configuration.table(tableName) .dataSource(dataSource) .validateOnMigrate(false) .target(MigrationVersion.LATEST) .outOfOrder(true) .locations("alfio/db/PGSQL/"); Flyway migration = new Flyway(configuration); migration.migrate(); return migration; }
Example 5
Source File: FlywayClassLoaderConfiguration.java From sbp with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean public FlywayMigrationStrategy migrationStrategy() { return flyway -> { FluentConfiguration alterConf = Flyway.configure(plugin.getWrapper().getPluginClassLoader()); alterConf.configuration(flyway.getConfiguration()); new Flyway(alterConf).migrate(); }; }
Example 6
Source File: FlywayExtensionConfigFixture.java From quarkus with Apache License 2.0 | 5 votes |
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 7
Source File: FlywayCreator.java From quarkus with Apache License 2.0 | 5 votes |
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 8
Source File: DatabaseJobHistoryStoreSchemaManager.java From incubator-gobblin with Apache License 2.0 | 4 votes |
private DatabaseJobHistoryStoreSchemaManager(Properties properties) { flyway = new Flyway(); flyway.configure(properties); flyway.setClassLoader(this.getClass().getClassLoader()); }
Example 9
Source File: FlywayFactory.java From dropwizard-flyway with Apache License 2.0 | 4 votes |
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; }