Search in sources :

Example 1 with Configuration

use of org.flywaydb.core.api.configuration.Configuration in project webofneeds by researchstudio-sat.

the class FlywayWrapper method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    if ("validate".equals(ddlStrategy.trim())) {
        Configuration config = Flyway.configure().dataSource(dataSource);
        Flyway flyway = new Flyway(config);
        flyway.migrate();
    } else {
        logger.info("Flyway DB Migration ommitted due to non-validate DDL-Strategy: " + ddlStrategy);
    }
}
Also used : Flyway(org.flywaydb.core.Flyway) Configuration(org.flywaydb.core.api.configuration.Configuration)

Example 2 with Configuration

use of org.flywaydb.core.api.configuration.Configuration in project flyway by flyway.

the class Main method main.

public static void main(String[] args) {
    CommandLineArguments commandLineArguments = new CommandLineArguments(args);
    initLogging(commandLineArguments);
    try {
        commandLineArguments.validate();
        if (commandLineArguments.hasOperation("help") || commandLineArguments.shouldPrintUsage()) {
            StringBuilder helpText = new StringBuilder();
            boolean helpAsVerbWithOperation = commandLineArguments.hasOperation("help") && commandLineArguments.getOperations().size() > 1;
            boolean helpAsFlagWithOperation = commandLineArguments.shouldPrintUsage() && commandLineArguments.getOperations().size() > 0;
            if (helpAsVerbWithOperation || helpAsFlagWithOperation) {
                for (String operation : commandLineArguments.getOperations()) {
                    String helpTextForOperation = PluginRegister.getPlugins(CommandExtension.class).stream().filter(e -> e.handlesCommand(operation)).map(CommandExtension::getHelpText).collect(Collectors.joining("\n\n"));
                    if (StringUtils.hasText(helpTextForOperation)) {
                        helpText.append(helpTextForOperation).append("\n\n");
                    }
                }
            }
            if (!StringUtils.hasText(helpText.toString())) {
                printUsage();
            } else {
                LOG.info(helpText.toString());
            }
            return;
        }
        Map<String, String> envVars = ConfigUtils.environmentVariablesToPropertyMap();
        Map<String, String> config = new HashMap<>();
        initializeDefaults(config, commandLineArguments);
        loadConfigurationFromConfigFiles(config, commandLineArguments, envVars);
        if (commandLineArguments.isWorkingDirectorySet()) {
            makeRelativeLocationsBasedOnWorkingDirectory(commandLineArguments, config);
        }
        config.putAll(envVars);
        config = overrideConfiguration(config, commandLineArguments.getConfiguration());
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        List<File> jarFiles = new ArrayList<>();
        jarFiles.addAll(getJdbcDriverJarFiles());
        jarFiles.addAll(getJavaMigrationJarFiles(config));
        if (!jarFiles.isEmpty()) {
            classLoader = ClassUtils.addJarsOrDirectoriesToClasspath(classLoader, jarFiles);
        }
        if (!commandLineArguments.shouldSuppressPrompt()) {
            promptForCredentialsIfMissing(config);
        }
        ConfigUtils.dumpConfiguration(config);
        filterProperties(config);
        Configuration configuration = new FluentConfiguration(classLoader).configuration(config);
        if (!commandLineArguments.skipCheckForUpdate()) {
            if (RedgateUpdateChecker.isEnabled() && configuration.getDataSource() != null) {
                JdbcConnectionFactory jdbcConnectionFactory = new JdbcConnectionFactory(configuration.getDataSource(), configuration, null);
                Database database = jdbcConnectionFactory.getDatabaseType().createDatabase(configuration, false, jdbcConnectionFactory, null);
                RedgateUpdateChecker.Context context = new RedgateUpdateChecker.Context(config.get(ConfigUtils.URL), commandLineArguments.getOperations(), database.getDatabaseType().getName(), database.getVersion().getVersion());
                RedgateUpdateChecker.checkForVersionUpdates(context);
            } else {
                MavenVersionChecker.checkForVersionUpdates();
            }
        }
        Flyway flyway = Flyway.configure(classLoader).configuration(configuration).load();
        OperationResultBase result;
        if (commandLineArguments.getOperations().size() == 1) {
            String operation = commandLineArguments.getOperations().get(0);
            result = executeOperation(flyway, operation, config, commandLineArguments);
        } else {
            result = new CompositeResult();
            for (String operation : commandLineArguments.getOperations()) {
                OperationResultBase individualResult = executeOperation(flyway, operation, config, commandLineArguments);
                ((CompositeResult) result).individualResults.add(individualResult);
            }
        }
        if (commandLineArguments.shouldOutputJson()) {
            printJson(commandLineArguments, result);
        }
    } catch (DbMigrate.FlywayMigrateException e) {
        MigrateErrorResult errorResult = ErrorOutput.fromMigrateException(e);
        printError(commandLineArguments, e, errorResult);
        System.exit(1);
    } catch (Exception e) {
        ErrorOutput errorOutput = ErrorOutput.fromException(e);
        printError(commandLineArguments, e, errorOutput);
        System.exit(1);
    } finally {
        flushLog(commandLineArguments);
    }
}
Also used : DbMigrate(org.flywaydb.core.internal.command.DbMigrate) Configuration(org.flywaydb.core.api.configuration.Configuration) FluentConfiguration(org.flywaydb.core.api.configuration.FluentConfiguration) Database(org.flywaydb.core.internal.database.base.Database) JdbcConnectionFactory(org.flywaydb.core.internal.jdbc.JdbcConnectionFactory) Flyway(org.flywaydb.core.Flyway) FlywayTrialExpiredException(org.flywaydb.core.internal.license.FlywayTrialExpiredException) IOException(java.io.IOException) FluentConfiguration(org.flywaydb.core.api.configuration.FluentConfiguration) File(java.io.File)

Example 3 with Configuration

use of org.flywaydb.core.api.configuration.Configuration in project spring-boot by spring-projects.

the class FlywayPropertiesTests method defaultValuesAreConsistent.

@SuppressWarnings("deprecation")
@Test
void defaultValuesAreConsistent() {
    FlywayProperties properties = new FlywayProperties();
    Configuration configuration = new FluentConfiguration();
    assertThat(configuration.isFailOnMissingLocations()).isEqualTo(properties.isFailOnMissingLocations());
    assertThat(properties.getLocations().stream().map(Location::new).toArray(Location[]::new)).isEqualTo(configuration.getLocations());
    assertThat(properties.getEncoding()).isEqualTo(configuration.getEncoding());
    assertThat(properties.getConnectRetries()).isEqualTo(configuration.getConnectRetries());
    // Can't assert connect retries interval as it is new in Flyway 7.15
    // Asserting hard-coded value in the metadata instead
    assertThat(configuration.getConnectRetriesInterval()).isEqualTo(120);
    // Can't assert lock retry count default as it is new in Flyway 7.1
    // Asserting hard-coded value in the metadata instead
    assertThat(configuration.getLockRetryCount()).isEqualTo(50);
    assertThat(properties.getDefaultSchema()).isEqualTo(configuration.getDefaultSchema());
    assertThat(properties.getSchemas()).isEqualTo(Arrays.asList(configuration.getSchemas()));
    assertThat(properties.isCreateSchemas()).isEqualTo(configuration.isCreateSchemas());
    assertThat(properties.getTable()).isEqualTo(configuration.getTable());
    assertThat(properties.getBaselineDescription()).isEqualTo(configuration.getBaselineDescription());
    assertThat(MigrationVersion.fromVersion(properties.getBaselineVersion())).isEqualTo(configuration.getBaselineVersion());
    assertThat(properties.getInstalledBy()).isEqualTo(configuration.getInstalledBy());
    assertThat(properties.getPlaceholders()).isEqualTo(configuration.getPlaceholders());
    assertThat(properties.getPlaceholderPrefix()).isEqualToIgnoringWhitespace(configuration.getPlaceholderPrefix());
    assertThat(properties.getPlaceholderSuffix()).isEqualTo(configuration.getPlaceholderSuffix());
    assertThat(properties.isPlaceholderReplacement()).isEqualTo(configuration.isPlaceholderReplacement());
    assertThat(properties.getSqlMigrationPrefix()).isEqualTo(configuration.getSqlMigrationPrefix());
    assertThat(properties.getSqlMigrationSuffixes()).isEqualTo(Arrays.asList(configuration.getSqlMigrationSuffixes()));
    assertThat(properties.getSqlMigrationSeparator()).isEqualTo(properties.getSqlMigrationSeparator());
    assertThat(properties.getRepeatableSqlMigrationPrefix()).isEqualTo(properties.getRepeatableSqlMigrationPrefix());
    assertThat(properties.getTarget()).isNull();
    assertThat(configuration.getTarget()).isNull();
    assertThat(configuration.getInitSql()).isNull();
    assertThat(properties.getInitSqls()).isEmpty();
    assertThat(configuration.isBaselineOnMigrate()).isEqualTo(properties.isBaselineOnMigrate());
    assertThat(configuration.isCleanDisabled()).isEqualTo(properties.isCleanDisabled());
    assertThat(configuration.isCleanOnValidationError()).isEqualTo(properties.isCleanOnValidationError());
    assertThat(configuration.isGroup()).isEqualTo(properties.isGroup());
    assertThat(configuration.isIgnoreMissingMigrations()).isEqualTo(properties.isIgnoreMissingMigrations());
    assertThat(configuration.isIgnoreIgnoredMigrations()).isEqualTo(properties.isIgnoreIgnoredMigrations());
    assertThat(configuration.isIgnorePendingMigrations()).isEqualTo(properties.isIgnorePendingMigrations());
    assertThat(configuration.isIgnoreFutureMigrations()).isEqualTo(properties.isIgnoreFutureMigrations());
    assertThat(configuration.isMixed()).isEqualTo(properties.isMixed());
    assertThat(configuration.isOutOfOrder()).isEqualTo(properties.isOutOfOrder());
    assertThat(configuration.isSkipDefaultCallbacks()).isEqualTo(properties.isSkipDefaultCallbacks());
    assertThat(configuration.isSkipDefaultResolvers()).isEqualTo(properties.isSkipDefaultResolvers());
    assertThat(configuration.isValidateMigrationNaming()).isEqualTo(properties.isValidateMigrationNaming());
    assertThat(configuration.isValidateOnMigrate()).isEqualTo(properties.isValidateOnMigrate());
    assertThat(properties.getDetectEncoding()).isNull();
    assertThat(configuration.getScriptPlaceholderPrefix()).isEqualTo("FP__");
    assertThat(configuration.getScriptPlaceholderSuffix()).isEqualTo("__");
}
Also used : FluentConfiguration(org.flywaydb.core.api.configuration.FluentConfiguration) ClassicConfiguration(org.flywaydb.core.api.configuration.ClassicConfiguration) Configuration(org.flywaydb.core.api.configuration.Configuration) FluentConfiguration(org.flywaydb.core.api.configuration.FluentConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with Configuration

use of org.flywaydb.core.api.configuration.Configuration in project flyway by flyway.

the class ResourceNameParser method populatePrefixes.

private List<Pair<String, ResourceType>> populatePrefixes(Configuration configuration) {
    List<Pair<String, ResourceType>> prefixes = new ArrayList<>();
    prefixes.add(Pair.of(configuration.getSqlMigrationPrefix(), ResourceType.MIGRATION));
    prefixes.add(Pair.of(configuration.getRepeatableSqlMigrationPrefix(), ResourceType.REPEATABLE_MIGRATION));
    for (Event event : Event.values()) {
        prefixes.add(Pair.of(event.getId(), ResourceType.CALLBACK));
    }
    Comparator<Pair<String, ResourceType>> prefixComparator = (p1, p2) -> {
        // Sort most-hard-to-match first; that is, in descending order of prefix length
        return p2.getLeft().length() - p1.getLeft().length();
    };
    prefixes.sort(prefixComparator);
    return prefixes;
}
Also used : Configuration(org.flywaydb.core.api.configuration.Configuration) MigrationVersion(org.flywaydb.core.api.MigrationVersion) java.util(java.util) Event(org.flywaydb.core.api.callback.Event) Pair(org.flywaydb.core.internal.util.Pair) Event(org.flywaydb.core.api.callback.Event) Pair(org.flywaydb.core.internal.util.Pair)

Aggregations

Configuration (org.flywaydb.core.api.configuration.Configuration)4 Flyway (org.flywaydb.core.Flyway)2 FluentConfiguration (org.flywaydb.core.api.configuration.FluentConfiguration)2 File (java.io.File)1 IOException (java.io.IOException)1 java.util (java.util)1 MigrationVersion (org.flywaydb.core.api.MigrationVersion)1 Event (org.flywaydb.core.api.callback.Event)1 ClassicConfiguration (org.flywaydb.core.api.configuration.ClassicConfiguration)1 DbMigrate (org.flywaydb.core.internal.command.DbMigrate)1 Database (org.flywaydb.core.internal.database.base.Database)1 JdbcConnectionFactory (org.flywaydb.core.internal.jdbc.JdbcConnectionFactory)1 FlywayTrialExpiredException (org.flywaydb.core.internal.license.FlywayTrialExpiredException)1 Pair (org.flywaydb.core.internal.util.Pair)1 Test (org.junit.jupiter.api.Test)1