From 3a56a07af6f9b6977d6ee5fe39ef3800f0535351 Mon Sep 17 00:00:00 2001 From: Gert-Jan Paulissen Date: Wed, 2 Sep 2020 09:45:28 +0200 Subject: [PATCH 1/8] Added flyway5. --- bootique-flyway/pom.xml | 4 + bootique-flyway5/pom.xml | 161 ++++++++++++++++++ .../io/bootique/flyway/FlywayFactory.java | 59 +++++++ .../java/io/bootique/flyway/FlywayModule.java | 60 +++++++ .../bootique/flyway/FlywayModuleProvider.java | 55 ++++++ .../java/io/bootique/flyway/FlywayRunner.java | 103 +++++++++++ .../io/bootique/flyway/FlywaySettings.java | 87 ++++++++++ .../flyway/command/BaselineCommand.java | 50 ++++++ .../bootique/flyway/command/CleanCommand.java | 50 ++++++ .../flyway/command/FlywayCommand.java | 44 +++++ .../bootique/flyway/command/InfoCommand.java | 49 ++++++ .../flyway/command/MigrateCommand.java | 50 ++++++ .../flyway/command/RepairCommand.java | 49 ++++++ .../flyway/command/ValidateCommand.java | 51 ++++++ .../services/io.bootique.BQModuleProvider | 1 + .../java/db/migration/V2__Update_table.java | 44 +++++ .../flyway/FlywayModuleProviderIT.java | 45 +++++ .../java/io/bootique/flyway/InfoTest.java | 113 ++++++++++++ .../java/io/bootique/flyway/MigrateTest.java | 98 +++++++++++ .../V2__Update_table_nonDefault.java | 33 ++++ .../test/resources/db/migration/V1__Init.sql | 21 +++ .../io/bootique/flyway/defaultMigration.yml | 25 +++ .../flyway/explicitDefaultMigration.yml | 27 +++ .../flyway/explicitNonDefaultMigration.yml | 27 +++ ...explicitNonDefaultMigrationConfigfile.conf | 1 + .../explicitNonDefaultMigrationConfigfile.yml | 29 ++++ .../io/bootique/flyway/verifyInfoMessage.yml | 38 +++++ .../resources/path/migration/V1__Init.sql | 21 +++ pom.xml | 2 +- 29 files changed, 1396 insertions(+), 1 deletion(-) create mode 100644 bootique-flyway5/pom.xml create mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/FlywayFactory.java create mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModule.java create mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModuleProvider.java create mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/FlywayRunner.java create mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/FlywaySettings.java create mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/BaselineCommand.java create mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/CleanCommand.java create mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/FlywayCommand.java create mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/InfoCommand.java create mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/MigrateCommand.java create mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/RepairCommand.java create mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/ValidateCommand.java create mode 100644 bootique-flyway5/src/main/resources/META-INF/services/io.bootique.BQModuleProvider create mode 100644 bootique-flyway5/src/test/java/db/migration/V2__Update_table.java create mode 100644 bootique-flyway5/src/test/java/io/bootique/flyway/FlywayModuleProviderIT.java create mode 100644 bootique-flyway5/src/test/java/io/bootique/flyway/InfoTest.java create mode 100644 bootique-flyway5/src/test/java/io/bootique/flyway/MigrateTest.java create mode 100644 bootique-flyway5/src/test/java/path/migration/V2__Update_table_nonDefault.java create mode 100644 bootique-flyway5/src/test/resources/db/migration/V1__Init.sql create mode 100644 bootique-flyway5/src/test/resources/io/bootique/flyway/defaultMigration.yml create mode 100644 bootique-flyway5/src/test/resources/io/bootique/flyway/explicitDefaultMigration.yml create mode 100644 bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigration.yml create mode 100644 bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.conf create mode 100644 bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.yml create mode 100644 bootique-flyway5/src/test/resources/io/bootique/flyway/verifyInfoMessage.yml create mode 100644 bootique-flyway5/src/test/resources/path/migration/V1__Init.sql diff --git a/bootique-flyway/pom.xml b/bootique-flyway/pom.xml index ad82e39..526cba3 100644 --- a/bootique-flyway/pom.xml +++ b/bootique-flyway/pom.xml @@ -35,6 +35,10 @@ Provides Flyway integration with Bootique. + + 6.5.0 + + diff --git a/bootique-flyway5/pom.xml b/bootique-flyway5/pom.xml new file mode 100644 index 0000000..80bbc73 --- /dev/null +++ b/bootique-flyway5/pom.xml @@ -0,0 +1,161 @@ + + + + + 4.0.0 + + + io.bootique.flyway + bootique-flyway-parent + 2.0-SNAPSHOT + + + bootique-flyway5 + jar + + bootique-flyway: Flyway5 Integration with Bootique + + Provides Flyway5 integration with Bootique. + + + + 5.1.4 + + + + + + io.bootique + bootique + compile + + + io.bootique.jdbc + bootique-jdbc + compile + + + org.flywaydb + flyway-core + compile + + + org.slf4j + slf4j-api + compile + + + + + junit + junit + test + + + org.mockito + mockito-core + test + + + io.bootique + bootique-test + test + + + com.h2database + h2 + test + + + io.bootique.jdbc + bootique-jdbc-test + test + + + io.bootique.jdbc + bootique-jdbc-tomcat + test + + + io.bootique.logback + bootique-logback + test + + + + + + + gpg + + + + org.apache.maven.plugins + maven-gpg-plugin + + + sign-artifacts + verify + + sign + + + + + + + + + + + flyway.version + 5.1.4 + + + + + + maven-resources-plugin + 3.2.0 + + + copy-resources + + validate + + copy-resources + + + ${basedir}/target/extra-resources + + + src/non-packaged-resources + true + + + + + + + + + + + diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayFactory.java b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayFactory.java new file mode 100644 index 0000000..ffe5988 --- /dev/null +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayFactory.java @@ -0,0 +1,59 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway; + +import io.bootique.annotation.BQConfig; +import io.bootique.annotation.BQConfigProperty; +import io.bootique.jdbc.DataSourceFactory; + +import javax.sql.DataSource; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.Map; +import java.util.HashMap; + +@BQConfig("Configures Flyway.") +public class FlywayFactory { + private List dataSources = new ArrayList(); + private List locations = Collections.singletonList("db/migration"); + private List configFiles = new ArrayList(); // list of config files to use + + FlywaySettings createDataSources(DataSourceFactory dataSourceFactory) { + final List dataSources = this.dataSources.stream().map(dataSourceFactory::forName).collect(Collectors.toList()); + return new FlywaySettings(dataSources, locations, configFiles); + } + + @BQConfigProperty("References to dataSources to access the database.") + public void setDataSources(List dataSources) { + this.dataSources = dataSources; + } + + @BQConfigProperty("The locations to scan recursively for migration scripts.") + public void setLocations(List locations) { + this.locations = locations; + } + + @BQConfigProperty("The list of Flyway configuration files to use.") + public void setConfigFiles(List configFiles) { + this.configFiles = configFiles; + } +} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModule.java b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModule.java new file mode 100644 index 0000000..6abd1a6 --- /dev/null +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModule.java @@ -0,0 +1,60 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway; + +import io.bootique.BQCoreModule; +import io.bootique.ConfigModule; +import io.bootique.config.ConfigurationFactory; +import io.bootique.di.Binder; +import io.bootique.di.Provides; +import io.bootique.flyway.command.BaselineCommand; +import io.bootique.flyway.command.CleanCommand; +import io.bootique.flyway.command.InfoCommand; +import io.bootique.flyway.command.MigrateCommand; +import io.bootique.flyway.command.RepairCommand; +import io.bootique.flyway.command.ValidateCommand; +import io.bootique.jdbc.DataSourceFactory; + +import static java.util.Arrays.asList; + +public class FlywayModule extends ConfigModule { + + @Override + public void configure(Binder binder) { + asList( + BaselineCommand.class, + CleanCommand.class, + InfoCommand.class, + MigrateCommand.class, + RepairCommand.class, + ValidateCommand.class + ).forEach(command -> BQCoreModule.extend(binder).addCommand(command)); + } + + @Provides + public FlywaySettings createFlywayDataSources(ConfigurationFactory configFactory, DataSourceFactory dataSourceFactory) { + return config(FlywayFactory.class, configFactory).createDataSources(dataSourceFactory); + } + + @Provides + public FlywayRunner createFlywayRunner(FlywaySettings flywaySettings) { + return new FlywayRunner(flywaySettings); + } +} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModuleProvider.java b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModuleProvider.java new file mode 100644 index 0000000..1b056a6 --- /dev/null +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModuleProvider.java @@ -0,0 +1,55 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway; + +import io.bootique.BQModuleMetadata; +import io.bootique.BQModuleProvider; +import io.bootique.di.BQModule; +import io.bootique.jdbc.JdbcModuleProvider; + +import java.lang.reflect.Type; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; + +public class FlywayModuleProvider implements BQModuleProvider { + + @Override + public BQModule module() { + return new FlywayModule(); + } + + @Override + public Map configs() { + return Collections.singletonMap("flyway", FlywayFactory.class); + } + + @Override + public Collection dependencies() { + return Collections.singletonList(new JdbcModuleProvider()); + } + + @Override + public BQModuleMetadata.Builder moduleBuilder() { + return BQModuleProvider.super + .moduleBuilder() + .description("Provides database migrations based on the Flyway library."); + } +} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayRunner.java b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayRunner.java new file mode 100644 index 0000000..69fe536 --- /dev/null +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayRunner.java @@ -0,0 +1,103 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway; + +import org.flywaydb.core.Flyway; +import org.flywaydb.core.api.MigrationInfoService; +import org.flywaydb.core.api.MigrationInfo; +import org.flywaydb.core.api.MigrationVersion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.flywaydb.core.internal.info.MigrationInfoDumper; + +import org.flywaydb.core.api.configuration.FluentConfiguration; + +import java.util.function.Consumer; + +public class FlywayRunner { + private final FlywaySettings settings; + + public FlywayRunner(FlywaySettings settings) { + this.settings = settings; + } + + public void migrate() { + forEach(Flyway::migrate); + } + + public void validate() { + forEach(Flyway::validate); + } + + public void baseline() { + forEach(Flyway::baseline); + } + + public void repair() { + forEach(Flyway::repair); + } + + public void info() { + settings.getDataSources().forEach(ds -> { + FluentConfiguration configuration = new FluentConfiguration(); + + Flyway flyway = new Flyway(configuration + .locations(settings.getLocations()) + .dataSource(ds) + .configure(settings.getProperties()) // takes precedence over location settings (do not use jdbc connection details though in a Flyway configuration file) + ); + + MigrationInfoService info = flyway.info(); + MigrationInfo current = info.current(); + MigrationVersion currentSchemaVersion = current == null ? MigrationVersion.EMPTY : current.getVersion(); + + MigrationVersion schemaVersionToOutput = currentSchemaVersion == null ? MigrationVersion.EMPTY : currentSchemaVersion; + + final Logger logger = LoggerFactory.getLogger(FlywayRunner.class); + + if(logger.isInfoEnabled()) { + logger.info("Schema version: " + schemaVersionToOutput); + logger.info(""); + + for (String line : MigrationInfoDumper.dumpToAsciiTable(info.all()).split("\\r?\\n")) { + logger.info(line); + } + } + }); + } + + public void clean() { + forEach(Flyway::clean); + } + + private void forEach(Consumer flywayConsumer) { + settings.getDataSources().forEach(ds -> { + FluentConfiguration configuration = new FluentConfiguration(); + + Flyway flyway = new Flyway(configuration + .locations(settings.getLocations()) + .dataSource(ds) + .configure(settings.getProperties()) // takes precedence over location settings (do not use jdbc connection details though in a Flyway configuration file) + ); + + flywayConsumer.accept(flyway); + }); + } +} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywaySettings.java b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywaySettings.java new file mode 100644 index 0000000..00dd337 --- /dev/null +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywaySettings.java @@ -0,0 +1,87 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway; + +import io.bootique.resource.ResourceFactory; + +import javax.sql.DataSource; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.HashMap; +import java.util.Properties; +import java.io.*; +import java.net.URL; + +import org.flywaydb.core.api.FlywayException; +import org.flywaydb.core.internal.util.FileCopyUtils; +import org.flywaydb.core.internal.configuration.ConfigUtils; + +public class FlywaySettings { + private final List dataSources; + private final String[] locations; + private final String[] configFiles; // list of config files to use + + public FlywaySettings(List dataSources, + List locations, + List configFiles) { + this.dataSources = Collections.unmodifiableList(dataSources); + this.locations = locations.toArray(new String[0]); + this.configFiles = configFiles.toArray(new String[0]); + } + + public List getDataSources() { + return dataSources; + } + + public String[] getLocations() { + return locations; + } + + public java.util.Map getProperties() { + Map config = new HashMap(); + + try { + for (String file : this.configFiles) { + URL url = new ResourceFactory(file).getUrl(); // file may have classpath: as a prefix + + Reader reader = new InputStreamReader(url.openStream()); + + // loadConfigurationFromReader() only available for Flyway 6 + // config.putAll(ConfigUtils.loadConfigurationFromReader(reader)); + + String errorMessage = "Unable to load config file: " + file; + + try { + String contents = FileCopyUtils.copyToString(reader); + Properties properties = new Properties(); + properties.load(new StringReader(contents.replace("\\", "\\\\"))); + return ConfigUtils.propertiesToMap(properties); + } catch (IOException e) { + throw new FlywayException(errorMessage, e); + } + } + } catch(IOException e) { + throw new RuntimeException(e); + } + + return config; + } +} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/BaselineCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/BaselineCommand.java new file mode 100644 index 0000000..abdbf55 --- /dev/null +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/command/BaselineCommand.java @@ -0,0 +1,50 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway.command; + +import javax.inject.Inject; +import javax.inject.Provider; + +import io.bootique.cli.Cli; +import io.bootique.command.CommandOutcome; +import io.bootique.command.CommandWithMetadata; +import io.bootique.flyway.FlywayRunner; +import io.bootique.meta.application.CommandMetadata; + +import static io.bootique.flyway.command.FlywayCommand.command; + +public class BaselineCommand extends CommandWithMetadata { + private Provider runnerProvider; + + @Inject + public BaselineCommand(Provider runnerProvider) { + super(CommandMetadata + .builder(BaselineCommand.class) + .description("Baselines an existing database, " + + "excluding all migrations up to and including baselineVersion.") + .build()); + this.runnerProvider = runnerProvider; + } + + @Override + public CommandOutcome run(Cli cli) { + return command(() -> runnerProvider.get().baseline()); + } +} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/CleanCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/CleanCommand.java new file mode 100644 index 0000000..5936c07 --- /dev/null +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/command/CleanCommand.java @@ -0,0 +1,50 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway.command; + +import javax.inject.Inject; +import javax.inject.Provider; + +import io.bootique.cli.Cli; +import io.bootique.command.CommandOutcome; +import io.bootique.command.CommandWithMetadata; +import io.bootique.flyway.FlywayRunner; +import io.bootique.meta.application.CommandMetadata; + +import static io.bootique.flyway.command.FlywayCommand.command; + +public class CleanCommand extends CommandWithMetadata { + private Provider runnerProvider; + + @Inject + public CleanCommand(Provider runnerProvider) { + super(CommandMetadata + .builder(CleanCommand.class) + .description("Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas." + + "The schemas are cleaned in the order specified by the schemas property.") + .build()); + this.runnerProvider = runnerProvider; + } + + @Override + public CommandOutcome run(Cli cli) { + return command(() -> runnerProvider.get().clean()); + } +} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/FlywayCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/FlywayCommand.java new file mode 100644 index 0000000..d5be9f5 --- /dev/null +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/command/FlywayCommand.java @@ -0,0 +1,44 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway.command; + +import io.bootique.command.CommandOutcome; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@FunctionalInterface +interface FlywayCommand { + Logger LOGGER = LoggerFactory.getLogger(FlywayCommand.class); + + /** + * SAM for passing operations inside command method. + */ + void apply() throws Exception; + + static CommandOutcome command(FlywayCommand command) { + try { + command.apply(); + return CommandOutcome.succeeded(); + } catch (Exception e) { + LOGGER.error("Error while executing command.", e); + return CommandOutcome.failed(1, e.getMessage()); + } + } +} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/InfoCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/InfoCommand.java new file mode 100644 index 0000000..af2a06a --- /dev/null +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/command/InfoCommand.java @@ -0,0 +1,49 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway.command; + +import javax.inject.Inject; +import javax.inject.Provider; + +import io.bootique.cli.Cli; +import io.bootique.command.CommandOutcome; +import io.bootique.command.CommandWithMetadata; +import io.bootique.flyway.FlywayRunner; +import io.bootique.meta.application.CommandMetadata; + +import static io.bootique.flyway.command.FlywayCommand.command; + +public class InfoCommand extends CommandWithMetadata { + private Provider runnerProvider; + + @Inject + public InfoCommand(Provider runnerProvider) { + super(CommandMetadata + .builder(InfoCommand.class) + .description("Prints the details and status information about all the migrations.") + .build()); + this.runnerProvider = runnerProvider; + } + + @Override + public CommandOutcome run(Cli cli) { + return command(() -> runnerProvider.get().info()); + } +} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/MigrateCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/MigrateCommand.java new file mode 100644 index 0000000..3fbbfb6 --- /dev/null +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/command/MigrateCommand.java @@ -0,0 +1,50 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway.command; + +import javax.inject.Inject; +import javax.inject.Provider; + +import io.bootique.cli.Cli; +import io.bootique.command.CommandOutcome; +import io.bootique.command.CommandWithMetadata; +import io.bootique.flyway.FlywayRunner; +import io.bootique.meta.application.CommandMetadata; + +import static io.bootique.flyway.command.FlywayCommand.command; + +public class MigrateCommand extends CommandWithMetadata { + private Provider runnerProvider; + + @Inject + public MigrateCommand(Provider runnerProvider) { + super(CommandMetadata + .builder(MigrateCommand.class) + .description("Migrates the schema to the latest version. " + + "Flyway will create the metadata table automatically if it doesn't exist.") + .build()); + this.runnerProvider = runnerProvider; + } + + @Override + public CommandOutcome run(Cli cli) { + return command(() -> runnerProvider.get().migrate()); + } +} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/RepairCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/RepairCommand.java new file mode 100644 index 0000000..7798c5c --- /dev/null +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/command/RepairCommand.java @@ -0,0 +1,49 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway.command; + +import javax.inject.Inject; +import javax.inject.Provider; + +import io.bootique.cli.Cli; +import io.bootique.command.CommandOutcome; +import io.bootique.command.CommandWithMetadata; +import io.bootique.flyway.FlywayRunner; +import io.bootique.meta.application.CommandMetadata; + +import static io.bootique.flyway.command.FlywayCommand.command; + +public class RepairCommand extends CommandWithMetadata { + private Provider runnerProvider; + + @Inject + public RepairCommand(Provider runnerProvider) { + super(CommandMetadata + .builder(RepairCommand.class) + .description("Repairs the metadata table.") + .build()); + this.runnerProvider = runnerProvider; + } + + @Override + public CommandOutcome run(Cli cli) { + return command(() -> runnerProvider.get().repair()); + } +} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/ValidateCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/ValidateCommand.java new file mode 100644 index 0000000..d7bcf31 --- /dev/null +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/command/ValidateCommand.java @@ -0,0 +1,51 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway.command; + +import javax.inject.Inject; +import javax.inject.Provider; + +import io.bootique.cli.Cli; +import io.bootique.command.CommandOutcome; +import io.bootique.command.CommandWithMetadata; +import io.bootique.flyway.FlywayRunner; +import io.bootique.meta.application.CommandMetadata; + +import static io.bootique.flyway.command.FlywayCommand.command; + +public class ValidateCommand extends CommandWithMetadata { + private Provider runnerProvider; + + @Inject + public ValidateCommand(Provider runnerProvider) { + super(CommandMetadata + .builder(ValidateCommand.class) + .description("Validate applied migrations against resolved ones " + + "(on the filesystem or classpath) to detect accidental " + + "changes that may prevent the schema(s) from being recreated exactly.") + .build()); + this.runnerProvider = runnerProvider; + } + + @Override + public CommandOutcome run(Cli cli) { + return command(() -> runnerProvider.get().validate()); + } +} diff --git a/bootique-flyway5/src/main/resources/META-INF/services/io.bootique.BQModuleProvider b/bootique-flyway5/src/main/resources/META-INF/services/io.bootique.BQModuleProvider new file mode 100644 index 0000000..98cbb48 --- /dev/null +++ b/bootique-flyway5/src/main/resources/META-INF/services/io.bootique.BQModuleProvider @@ -0,0 +1 @@ +io.bootique.flyway.FlywayModuleProvider \ No newline at end of file diff --git a/bootique-flyway5/src/test/java/db/migration/V2__Update_table.java b/bootique-flyway5/src/test/java/db/migration/V2__Update_table.java new file mode 100644 index 0000000..c5e3967 --- /dev/null +++ b/bootique-flyway5/src/test/java/db/migration/V2__Update_table.java @@ -0,0 +1,44 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package db.migration; + +import org.flywaydb.core.api.migration.jdbc.JdbcMigration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +public class V2__Update_table implements JdbcMigration { + private static Logger LOGGER = LoggerFactory.getLogger(V2__Update_table.class); + + @Override + public void migrate(Connection connection) { + String insertSQL = "INSERT INTO TEST (id, name) VALUES (2, 'Test 2')"; + + try (PreparedStatement statement = connection.prepareStatement(insertSQL)) { + statement.execute(); + } catch (SQLException e) { + LOGGER.error("Migration failed", e); + throw new RuntimeException(e); + } + } +} \ No newline at end of file diff --git a/bootique-flyway5/src/test/java/io/bootique/flyway/FlywayModuleProviderIT.java b/bootique-flyway5/src/test/java/io/bootique/flyway/FlywayModuleProviderIT.java new file mode 100644 index 0000000..34b817b --- /dev/null +++ b/bootique-flyway5/src/test/java/io/bootique/flyway/FlywayModuleProviderIT.java @@ -0,0 +1,45 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway; + +import io.bootique.BQRuntime; +import io.bootique.jdbc.JdbcModule; +import io.bootique.test.junit.BQModuleProviderChecker; +import io.bootique.test.junit.BQRuntimeChecker; +import io.bootique.test.junit.BQTestFactory; +import org.junit.Rule; +import org.junit.Test; + +public class FlywayModuleProviderIT { + + @Rule + public BQTestFactory testFactory = new BQTestFactory(); + + @Test + public void testAutoLoadable() { + BQModuleProviderChecker.testAutoLoadable(FlywayModuleProvider.class); + } + + @Test + public void testModuleDeclaresDependencies() { + final BQRuntime bqRuntime = testFactory.app().moduleProvider(new FlywayModuleProvider()).createRuntime(); + BQRuntimeChecker.testModulesLoaded(bqRuntime, JdbcModule.class, FlywayModule.class); + } +} diff --git a/bootique-flyway5/src/test/java/io/bootique/flyway/InfoTest.java b/bootique-flyway5/src/test/java/io/bootique/flyway/InfoTest.java new file mode 100644 index 0000000..a3c0dc8 --- /dev/null +++ b/bootique-flyway5/src/test/java/io/bootique/flyway/InfoTest.java @@ -0,0 +1,113 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway; + +import io.bootique.BQRuntime; +import io.bootique.command.CommandOutcome; +import io.bootique.test.junit.BQTestFactory; +import org.junit.Rule; +import org.junit.Test; + +import java.util.Scanner; +import java.io.File; +import java.io.FileNotFoundException; + +import static org.junit.Assert.assertTrue; + +/** + * Tests for info command. + * + * @author Gert-Jan Paulissen + */ +public class InfoTest { + + @Rule + public final BQTestFactory testFactory = new BQTestFactory(); + + @Test + public void verifyInfoMessage() { + BQRuntime runtime; + + testFactory + .app("--config=classpath:io/bootique/flyway/verifyInfoMessage.yml", "--clean") + .autoLoadModules() + .run(); + + runtime = testFactory + .app("--config=classpath:io/bootique/flyway/verifyInfoMessage.yml", "--info") + .autoLoadModules() + .createRuntime(); + + testInfoCommand(runtime, 1); + + testFactory + .app("--config=classpath:io/bootique/flyway/verifyInfoMessage.yml", "--migrate") + .autoLoadModules() + .run(); + + runtime = testFactory + .app("--config=classpath:io/bootique/flyway/verifyInfoMessage.yml", "--info") + .autoLoadModules() + .createRuntime(); + + testInfoCommand(runtime, 2); + } + + private void testInfoCommand(BQRuntime runtime, int which) { + CommandOutcome result = runtime.run(); + assertTrue(result.isSuccess()); + + if (which == 1) { + assertTrue(textFoundInLogFile("+-----------+---------+--------------+------+--------------+---------+")); + assertTrue(textFoundInLogFile("| Category | Version | Description | Type | Installed On | State |")); + assertTrue(textFoundInLogFile("+-----------+---------+--------------+------+--------------+---------+")); + assertTrue(textFoundInLogFile("| Versioned | 1 | Init | SQL | | Pending |")); + assertTrue(textFoundInLogFile("| Versioned | 2 | Update table | JDBC | | Pending |")); + assertTrue(textFoundInLogFile("+-----------+---------+--------------+------+--------------+---------+")); + } else { + assertTrue(textFoundInLogFile("+-----------+---------+--------------+------+---------------------+---------+")); + assertTrue(textFoundInLogFile("| Category | Version | Description | Type | Installed On | State |")); + assertTrue(textFoundInLogFile("+-----------+---------+--------------+------+---------------------+---------+")); + assertTrue(textFoundInLogFile("| Versioned | 1 | Init | SQL | .......... ........ | Success |")); + assertTrue(textFoundInLogFile("| Versioned | 2 | Update table | JDBC | .......... ........ | Success |")); + assertTrue(textFoundInLogFile("+-----------+---------+--------------+------+---------------------+---------+")); + } + } + + private boolean textFoundInLogFile(String text) { + try { + Scanner scanner = new Scanner(new File("target/test.log")); + String pattern = text.replace("+", "\\+").replace("|", "\\|"); + + //now read the file line by line... + while (scanner.hasNextLine()) { + if (scanner.nextLine().matches("^.*" + pattern + "$")) + { + return true; + } + } + + } catch(FileNotFoundException e) { + return false; + } + + return false; + } +} diff --git a/bootique-flyway5/src/test/java/io/bootique/flyway/MigrateTest.java b/bootique-flyway5/src/test/java/io/bootique/flyway/MigrateTest.java new file mode 100644 index 0000000..f840d3b --- /dev/null +++ b/bootique-flyway5/src/test/java/io/bootique/flyway/MigrateTest.java @@ -0,0 +1,98 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.bootique.flyway; + +import io.bootique.BQRuntime; +import io.bootique.command.CommandOutcome; +import io.bootique.jdbc.test.DatabaseChannel; +import io.bootique.jdbc.test.Table; +import io.bootique.test.junit.BQTestFactory; +import org.junit.Rule; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Tests for migrate command. + * + * @author Ibragimov Ruslan + */ +public class MigrateTest { + + @Rule + public final BQTestFactory testFactory = new BQTestFactory(); + + @Test + public void defaultMigration() { + BQRuntime runtime = testFactory + .app("--config=classpath:io/bootique/flyway/defaultMigration.yml", "--migrate") + .autoLoadModules() + .createRuntime(); + + testMigrateCommand(runtime); + } + + @Test + public void explicitDefaultMigration() { + BQRuntime runtime = testFactory + .app("--config=classpath:io/bootique/flyway/explicitDefaultMigration.yml", "--migrate") + .autoLoadModules() + .createRuntime(); + + testMigrateCommand(runtime); + } + + @Test + public void explicitNonDefaultMigration() { + BQRuntime runtime = testFactory + .app("--config=classpath:io/bootique/flyway/explicitNonDefaultMigration.yml", "--migrate") + .autoLoadModules() + .createRuntime(); + + testMigrateCommand(runtime); + } + + @Test + public void explicitNonDefaultMigrationConfigfile() { + BQRuntime runtime = testFactory + .app("--config=classpath:io/bootique/flyway/explicitNonDefaultMigrationConfigfile.yml", "--migrate") + .autoLoadModules() + .createRuntime(); + + testMigrateCommand(runtime); + } + + private void testMigrateCommand(BQRuntime runtime) { + CommandOutcome result = runtime.run(); + assertTrue(result.isSuccess()); + + Table a = DatabaseChannel.get(runtime).newTable("TEST").columnNames("ID", "NAME").build(); + List row = a.select(); + assertEquals(1, row.get(0)[0]); + assertEquals("Test", row.get(0)[1]); + assertEquals(2, row.get(1)[0]); + assertEquals("Test 2", row.get(1)[1]); + + a.matcher().assertMatches(2); + } +} diff --git a/bootique-flyway5/src/test/java/path/migration/V2__Update_table_nonDefault.java b/bootique-flyway5/src/test/java/path/migration/V2__Update_table_nonDefault.java new file mode 100644 index 0000000..70693ce --- /dev/null +++ b/bootique-flyway5/src/test/java/path/migration/V2__Update_table_nonDefault.java @@ -0,0 +1,33 @@ +/* + * Licensed to ObjectStyle LLC under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ObjectStyle LLC licenses + * this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package path.migration; + +import db.migration.V2__Update_table; +import org.flywaydb.core.api.migration.jdbc.JdbcMigration; + +import java.sql.Connection; + +public class V2__Update_table_nonDefault implements JdbcMigration { + + @Override + public void migrate(Connection connection) { + new V2__Update_table().migrate(connection); + } +} \ No newline at end of file diff --git a/bootique-flyway5/src/test/resources/db/migration/V1__Init.sql b/bootique-flyway5/src/test/resources/db/migration/V1__Init.sql new file mode 100644 index 0000000..31d7916 --- /dev/null +++ b/bootique-flyway5/src/test/resources/db/migration/V1__Init.sql @@ -0,0 +1,21 @@ +--Licensed to ObjectStyle LLC under one +--or more contributor license agreements. See the NOTICE file +--distributed with this work for additional information +--regarding copyright ownership. The ObjectStyle LLC licenses +--this file to you under the Apache License, Version 2.0 (the +--"License"); you may not use this file except in compliance +--with the License. You may obtain a copy of the License at +-- http://www.apache.org/licenses/LICENSE-2.0 +--Unless required by applicable law or agreed to in writing, +--software distributed under the License is distributed on an +--"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +--KIND, either express or implied. See the License for the +--specific language governing permissions and limitations +--under the License. + +CREATE TABLE TEST ( + ID INT PRIMARY KEY, + NAME VARCHAR(255) +); + +INSERT INTO TEST VALUES (1, 'Test'); \ No newline at end of file diff --git a/bootique-flyway5/src/test/resources/io/bootique/flyway/defaultMigration.yml b/bootique-flyway5/src/test/resources/io/bootique/flyway/defaultMigration.yml new file mode 100644 index 0000000..34c2dee --- /dev/null +++ b/bootique-flyway5/src/test/resources/io/bootique/flyway/defaultMigration.yml @@ -0,0 +1,25 @@ +# Licensed to ObjectStyle LLC under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ObjectStyle LLC licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +jdbc: + test: + url: jdbc:h2:mem:defaultMigration + username: '' + password: '' + driverClassName: org.h2.Driver + +flyway: + dataSources: + - test \ No newline at end of file diff --git a/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitDefaultMigration.yml b/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitDefaultMigration.yml new file mode 100644 index 0000000..71e2681 --- /dev/null +++ b/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitDefaultMigration.yml @@ -0,0 +1,27 @@ +# Licensed to ObjectStyle LLC under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ObjectStyle LLC licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +jdbc: + test: + url: jdbc:h2:mem:defaultMigration + username: '' + password: '' + driverClassName: org.h2.Driver + +flyway: + locations: + - db/migration + dataSources: + - test \ No newline at end of file diff --git a/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigration.yml b/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigration.yml new file mode 100644 index 0000000..55fabe1 --- /dev/null +++ b/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigration.yml @@ -0,0 +1,27 @@ +# Licensed to ObjectStyle LLC under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ObjectStyle LLC licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +jdbc: + test: + url: jdbc:h2:mem:defaultMigration + username: '' + password: '' + driverClassName: org.h2.Driver + +flyway: + locations: + - path/migration + dataSources: + - test \ No newline at end of file diff --git a/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.conf b/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.conf new file mode 100644 index 0000000..cdfc237 --- /dev/null +++ b/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.conf @@ -0,0 +1 @@ +flyway.locations = path/migration diff --git a/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.yml b/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.yml new file mode 100644 index 0000000..756faf4 --- /dev/null +++ b/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.yml @@ -0,0 +1,29 @@ +# Licensed to ObjectStyle LLC under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ObjectStyle LLC licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +jdbc: + test: + url: jdbc:h2:mem:defaultMigration + username: bogus + password: bogus + driverClassName: org.h2.Driver + +flyway: + locations: + - bogus + configFiles: + - classpath:io/bootique/flyway/explicitNonDefaultMigrationConfigfile.conf + dataSources: + - test diff --git a/bootique-flyway5/src/test/resources/io/bootique/flyway/verifyInfoMessage.yml b/bootique-flyway5/src/test/resources/io/bootique/flyway/verifyInfoMessage.yml new file mode 100644 index 0000000..c2509ea --- /dev/null +++ b/bootique-flyway5/src/test/resources/io/bootique/flyway/verifyInfoMessage.yml @@ -0,0 +1,38 @@ +# Licensed to ObjectStyle LLC under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ObjectStyle LLC licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +jdbc: + test: + url: jdbc:h2:mem:defaultMigration + username: '' + password: '' + driverClassName: org.h2.Driver + +flyway: + dataSources: + - test + +log: + level: warn + loggers: + io.bootique.flyway: + level: info + appenderRefs: + - test + appenders: + - type: file + name: test + logFormat: '%c{20}: %m%n' + file: target/test.log diff --git a/bootique-flyway5/src/test/resources/path/migration/V1__Init.sql b/bootique-flyway5/src/test/resources/path/migration/V1__Init.sql new file mode 100644 index 0000000..31d7916 --- /dev/null +++ b/bootique-flyway5/src/test/resources/path/migration/V1__Init.sql @@ -0,0 +1,21 @@ +--Licensed to ObjectStyle LLC under one +--or more contributor license agreements. See the NOTICE file +--distributed with this work for additional information +--regarding copyright ownership. The ObjectStyle LLC licenses +--this file to you under the Apache License, Version 2.0 (the +--"License"); you may not use this file except in compliance +--with the License. You may obtain a copy of the License at +-- http://www.apache.org/licenses/LICENSE-2.0 +--Unless required by applicable law or agreed to in writing, +--software distributed under the License is distributed on an +--"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +--KIND, either express or implied. See the License for the +--specific language governing permissions and limitations +--under the License. + +CREATE TABLE TEST ( + ID INT PRIMARY KEY, + NAME VARCHAR(255) +); + +INSERT INTO TEST VALUES (1, 'Test'); \ No newline at end of file diff --git a/pom.xml b/pom.xml index efeb585..7037490 100644 --- a/pom.xml +++ b/pom.xml @@ -39,11 +39,11 @@ bootique-flyway + bootique-flyway5 ${project.version} - 6.5.0 1.4.200 From 8e427a218253cc5c0b23fbc140d73ff04046b765 Mon Sep 17 00:00:00 2001 From: Gert-Jan Paulissen Date: Wed, 2 Sep 2020 12:27:23 +0200 Subject: [PATCH 2/8] Added logging the configuration. --- .../java/io/bootique/flyway/FlywayRunner.java | 10 ++-- .../io/bootique/flyway/FlywaySettings.java | 46 ++++++++++++++----- .../java/io/bootique/flyway/FlywayRunner.java | 12 ++--- .../io/bootique/flyway/FlywaySettings.java | 45 +++++++++++++----- 4 files changed, 80 insertions(+), 33 deletions(-) diff --git a/bootique-flyway/src/main/java/io/bootique/flyway/FlywayRunner.java b/bootique-flyway/src/main/java/io/bootique/flyway/FlywayRunner.java index 62a4d01..d529400 100644 --- a/bootique-flyway/src/main/java/io/bootique/flyway/FlywayRunner.java +++ b/bootique-flyway/src/main/java/io/bootique/flyway/FlywayRunner.java @@ -20,16 +20,19 @@ package io.bootique.flyway; import org.flywaydb.core.Flyway; -import org.flywaydb.core.api.MigrationInfoService; import org.flywaydb.core.api.MigrationInfo; +import org.flywaydb.core.api.MigrationInfoService; import org.flywaydb.core.api.MigrationVersion; +import org.flywaydb.core.internal.info.MigrationInfoDumper; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.flywaydb.core.internal.info.MigrationInfoDumper; import java.util.function.Consumer; public class FlywayRunner { + private static Logger logger = LoggerFactory.getLogger(FlywayRunner.class); + private final FlywaySettings settings; public FlywayRunner(FlywaySettings settings) { @@ -66,8 +69,6 @@ public void info() { MigrationVersion schemaVersionToOutput = currentSchemaVersion == null ? MigrationVersion.EMPTY : currentSchemaVersion; - final Logger logger = LoggerFactory.getLogger(FlywayRunner.class); - if(logger.isInfoEnabled()) { logger.info("Schema version: " + schemaVersionToOutput); logger.info(""); @@ -90,6 +91,7 @@ private void forEach(Consumer flywayConsumer) { .dataSource(ds) .configuration(settings.getProperties()) // takes precedence over location settings (do not use jdbc connection details though in a Flyway configuration file) ); + flywayConsumer.accept(flyway); }); } diff --git a/bootique-flyway/src/main/java/io/bootique/flyway/FlywaySettings.java b/bootique-flyway/src/main/java/io/bootique/flyway/FlywaySettings.java index d481bff..ac7590c 100644 --- a/bootique-flyway/src/main/java/io/bootique/flyway/FlywaySettings.java +++ b/bootique-flyway/src/main/java/io/bootique/flyway/FlywaySettings.java @@ -21,17 +21,25 @@ import io.bootique.resource.ResourceFactory; -import javax.sql.DataSource; +import java.io.*; +import java.net.URL; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.HashMap; -import java.io.*; -import java.net.URL; +import java.util.TreeMap; +import javax.sql.DataSource; +import org.flywaydb.core.api.FlywayException; import org.flywaydb.core.internal.configuration.ConfigUtils; +import org.flywaydb.core.internal.util.StringUtils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class FlywaySettings { + private static Logger logger = LoggerFactory.getLogger(FlywayRunner.class); + private final List dataSources; private final String[] locations; private final String[] configFiles; // list of config files to use @@ -55,19 +63,35 @@ public String[] getLocations() { public java.util.Map getProperties() { Map config = new HashMap(); - try { - for (String file : this.configFiles) { - URL url = new ResourceFactory(file).getUrl(); // file may have classpath: as a prefix + for (String file : this.configFiles) { + final String errorMessage = "Unable to load config file: " + file; + + try { + final URL url = new ResourceFactory(file).getUrl(); // file may have classpath: as a prefix + final Reader reader = new InputStreamReader(url.openStream()); - Reader reader = new InputStreamReader(url.openStream()); config.putAll(ConfigUtils.loadConfigurationFromReader(reader)); + } catch(IOException e) { + throw new FlywayException(errorMessage, e); } - } catch(IOException e) { - throw new RuntimeException(e); } - ConfigUtils.dumpConfiguration(config); + dumpConfiguration(config); return config; } + + /** + * Dumps the configuration to the console when debug output is activated. + * + * @param config The configured properties. + */ + private static void dumpConfiguration(Map config) { + if (logger.isDebugEnabled()) { + logger.debug("Using configuration:"); + for (Map.Entry entry : new TreeMap<>(config).entrySet()) { + logger.debug(entry.getKey() + " -> " + entry.getValue()); + } + } + } } diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayRunner.java b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayRunner.java index 69fe536..dbec38a 100644 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayRunner.java +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayRunner.java @@ -20,18 +20,20 @@ package io.bootique.flyway; import org.flywaydb.core.Flyway; -import org.flywaydb.core.api.MigrationInfoService; import org.flywaydb.core.api.MigrationInfo; +import org.flywaydb.core.api.MigrationInfoService; import org.flywaydb.core.api.MigrationVersion; +import org.flywaydb.core.api.configuration.FluentConfiguration; +import org.flywaydb.core.internal.info.MigrationInfoDumper; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.flywaydb.core.internal.info.MigrationInfoDumper; -import org.flywaydb.core.api.configuration.FluentConfiguration; - import java.util.function.Consumer; public class FlywayRunner { + private static Logger logger = LoggerFactory.getLogger(FlywayRunner.class); + private final FlywaySettings settings; public FlywayRunner(FlywaySettings settings) { @@ -70,8 +72,6 @@ public void info() { MigrationVersion schemaVersionToOutput = currentSchemaVersion == null ? MigrationVersion.EMPTY : currentSchemaVersion; - final Logger logger = LoggerFactory.getLogger(FlywayRunner.class); - if(logger.isInfoEnabled()) { logger.info("Schema version: " + schemaVersionToOutput); logger.info(""); diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywaySettings.java b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywaySettings.java index 00dd337..7eae97d 100644 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywaySettings.java +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywaySettings.java @@ -21,20 +21,27 @@ import io.bootique.resource.ResourceFactory; -import javax.sql.DataSource; +import java.io.*; +import java.net.URL; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.HashMap; import java.util.Properties; -import java.io.*; -import java.net.URL; +import java.util.TreeMap; +import javax.sql.DataSource; import org.flywaydb.core.api.FlywayException; -import org.flywaydb.core.internal.util.FileCopyUtils; import org.flywaydb.core.internal.configuration.ConfigUtils; +import org.flywaydb.core.internal.util.FileCopyUtils; +import org.flywaydb.core.internal.util.StringUtils; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class FlywaySettings { + private static Logger logger = LoggerFactory.getLogger(FlywayRunner.class); + private final List dataSources; private final String[] locations; private final String[] configFiles; // list of config files to use @@ -60,21 +67,19 @@ public java.util.Map getProperties() { try { for (String file : this.configFiles) { - URL url = new ResourceFactory(file).getUrl(); // file may have classpath: as a prefix - - Reader reader = new InputStreamReader(url.openStream()); + final String errorMessage = "Unable to load config file: " + file; + final URL url = new ResourceFactory(file).getUrl(); // file may have classpath: as a prefix + final Reader reader = new InputStreamReader(url.openStream()); // loadConfigurationFromReader() only available for Flyway 6 // config.putAll(ConfigUtils.loadConfigurationFromReader(reader)); - String errorMessage = "Unable to load config file: " + file; - try { String contents = FileCopyUtils.copyToString(reader); Properties properties = new Properties(); properties.load(new StringReader(contents.replace("\\", "\\\\"))); - return ConfigUtils.propertiesToMap(properties); - } catch (IOException e) { + config.putAll(ConfigUtils.propertiesToMap(properties)); + } catch(IOException e) { throw new FlywayException(errorMessage, e); } } @@ -82,6 +87,22 @@ public java.util.Map getProperties() { throw new RuntimeException(e); } + dumpConfiguration(config); + return config; } + + /** + * Dumps the configuration to the console when debug output is activated. + * + * @param config The configured properties. + */ + private static void dumpConfiguration(Map config) { + if (logger.isDebugEnabled()) { + logger.debug("Using configuration:"); + for (Map.Entry entry : new TreeMap<>(config).entrySet()) { + logger.debug(entry.getKey() + " -> " + entry.getValue()); + } + } + } } From cb080480b1d9873a56fc93a111802cd442fcffc3 Mon Sep 17 00:00:00 2001 From: Gert-Jan Paulissen Date: Wed, 2 Sep 2020 12:59:43 +0200 Subject: [PATCH 3/8] Removed obsolete profile. --- bootique-flyway5/pom.xml | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/bootique-flyway5/pom.xml b/bootique-flyway5/pom.xml index 80bbc73..e25c7e5 100644 --- a/bootique-flyway5/pom.xml +++ b/bootique-flyway5/pom.xml @@ -122,40 +122,5 @@ - - - - flyway.version - 5.1.4 - - - - - - maven-resources-plugin - 3.2.0 - - - copy-resources - - validate - - copy-resources - - - ${basedir}/target/extra-resources - - - src/non-packaged-resources - true - - - - - - - - - From ca1828c67c3ff45150d63440329e479dcba91ca9 Mon Sep 17 00:00:00 2001 From: Gert-Jan Paulissen Date: Wed, 2 Sep 2020 13:59:33 +0200 Subject: [PATCH 4/8] Enhanced debugging. --- .../io/bootique/flyway/FlywaySettings.java | 14 ++++--- .../io/bootique/flyway/FlywaySettings.java | 37 ++++++++++--------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/bootique-flyway/src/main/java/io/bootique/flyway/FlywaySettings.java b/bootique-flyway/src/main/java/io/bootique/flyway/FlywaySettings.java index ac7590c..b21e076 100644 --- a/bootique-flyway/src/main/java/io/bootique/flyway/FlywaySettings.java +++ b/bootique-flyway/src/main/java/io/bootique/flyway/FlywaySettings.java @@ -69,14 +69,17 @@ public java.util.Map getProperties() { try { final URL url = new ResourceFactory(file).getUrl(); // file may have classpath: as a prefix final Reader reader = new InputStreamReader(url.openStream()); - - config.putAll(ConfigUtils.loadConfigurationFromReader(reader)); + + final Map fileConfig = ConfigUtils.loadConfigurationFromReader(reader); + + config.putAll(fileConfig); + dumpConfiguration(fileConfig, file); } catch(IOException e) { throw new FlywayException(errorMessage, e); } } - dumpConfiguration(config); + dumpConfiguration(config, "ALL"); return config; } @@ -85,10 +88,11 @@ public java.util.Map getProperties() { * Dumps the configuration to the console when debug output is activated. * * @param config The configured properties. + * @param resource The config file resource. */ - private static void dumpConfiguration(Map config) { + private static void dumpConfiguration(Map config, String resource) { if (logger.isDebugEnabled()) { - logger.debug("Using configuration:"); + logger.debug("Using configuration resource " + resource); for (Map.Entry entry : new TreeMap<>(config).entrySet()) { logger.debug(entry.getKey() + " -> " + entry.getValue()); } diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywaySettings.java b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywaySettings.java index 7eae97d..cb509cd 100644 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywaySettings.java +++ b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywaySettings.java @@ -65,29 +65,31 @@ public String[] getLocations() { public java.util.Map getProperties() { Map config = new HashMap(); - try { - for (String file : this.configFiles) { - final String errorMessage = "Unable to load config file: " + file; + for (String file : this.configFiles) { + final String errorMessage = "Unable to load config file: " + file; + + try { final URL url = new ResourceFactory(file).getUrl(); // file may have classpath: as a prefix final Reader reader = new InputStreamReader(url.openStream()); // loadConfigurationFromReader() only available for Flyway 6 // config.putAll(ConfigUtils.loadConfigurationFromReader(reader)); - - try { - String contents = FileCopyUtils.copyToString(reader); - Properties properties = new Properties(); - properties.load(new StringReader(contents.replace("\\", "\\\\"))); - config.putAll(ConfigUtils.propertiesToMap(properties)); - } catch(IOException e) { - throw new FlywayException(errorMessage, e); - } + + final String contents = FileCopyUtils.copyToString(reader); + final Properties properties = new Properties(); + + properties.load(new StringReader(contents.replace("\\", "\\\\"))); + + final Map fileConfig = ConfigUtils.propertiesToMap(properties); + + config.putAll(fileConfig); + dumpConfiguration(fileConfig, file); + } catch(IOException e) { + throw new FlywayException(errorMessage, e); } - } catch(IOException e) { - throw new RuntimeException(e); } - dumpConfiguration(config); + dumpConfiguration(config, "ALL"); return config; } @@ -96,10 +98,11 @@ public java.util.Map getProperties() { * Dumps the configuration to the console when debug output is activated. * * @param config The configured properties. + * @param resource The config file resource. */ - private static void dumpConfiguration(Map config) { + private static void dumpConfiguration(Map config, String resource) { if (logger.isDebugEnabled()) { - logger.debug("Using configuration:"); + logger.debug("Using configuration resource " + resource); for (Map.Entry entry : new TreeMap<>(config).entrySet()) { logger.debug(entry.getKey() + " -> " + entry.getValue()); } From 802683aa84668444ccf4f63ab05fc4eb10ec93e1 Mon Sep 17 00:00:00 2001 From: Gert-Jan Paulissen Date: Fri, 4 Sep 2020 12:17:05 +0200 Subject: [PATCH 5/8] Let bootique flyway 5 depend on bootique flyway 6. --- bootique-flyway/pom.xml | 19 +++ bootique-flyway5/pom.xml | 13 ++ .../io/bootique/flyway/FlywayFactory.java | 59 --------- .../java/io/bootique/flyway/FlywayModule.java | 60 ---------- .../bootique/flyway/FlywayModuleProvider.java | 55 --------- .../flyway/command/BaselineCommand.java | 50 -------- .../bootique/flyway/command/CleanCommand.java | 50 -------- .../flyway/command/FlywayCommand.java | 44 ------- .../bootique/flyway/command/InfoCommand.java | 49 -------- .../flyway/command/MigrateCommand.java | 50 -------- .../flyway/command/RepairCommand.java | 49 -------- .../flyway/command/ValidateCommand.java | 51 -------- .../services/io.bootique.BQModuleProvider | 1 - .../flyway/FlywayModuleProviderIT.java | 45 ------- .../java/io/bootique/flyway/InfoTest.java | 113 ------------------ .../java/io/bootique/flyway/MigrateTest.java | 98 --------------- .../test/resources/db/migration/V1__Init.sql | 21 ---- .../io/bootique/flyway/defaultMigration.yml | 25 ---- .../flyway/explicitDefaultMigration.yml | 27 ----- .../flyway/explicitNonDefaultMigration.yml | 27 ----- ...explicitNonDefaultMigrationConfigfile.conf | 1 - .../explicitNonDefaultMigrationConfigfile.yml | 29 ----- .../io/bootique/flyway/verifyInfoMessage.yml | 38 ------ .../resources/path/migration/V1__Init.sql | 21 ---- 24 files changed, 32 insertions(+), 963 deletions(-) delete mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/FlywayFactory.java delete mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModule.java delete mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModuleProvider.java delete mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/BaselineCommand.java delete mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/CleanCommand.java delete mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/FlywayCommand.java delete mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/InfoCommand.java delete mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/MigrateCommand.java delete mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/RepairCommand.java delete mode 100644 bootique-flyway5/src/main/java/io/bootique/flyway/command/ValidateCommand.java delete mode 100644 bootique-flyway5/src/main/resources/META-INF/services/io.bootique.BQModuleProvider delete mode 100644 bootique-flyway5/src/test/java/io/bootique/flyway/FlywayModuleProviderIT.java delete mode 100644 bootique-flyway5/src/test/java/io/bootique/flyway/InfoTest.java delete mode 100644 bootique-flyway5/src/test/java/io/bootique/flyway/MigrateTest.java delete mode 100644 bootique-flyway5/src/test/resources/db/migration/V1__Init.sql delete mode 100644 bootique-flyway5/src/test/resources/io/bootique/flyway/defaultMigration.yml delete mode 100644 bootique-flyway5/src/test/resources/io/bootique/flyway/explicitDefaultMigration.yml delete mode 100644 bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigration.yml delete mode 100644 bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.conf delete mode 100644 bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.yml delete mode 100644 bootique-flyway5/src/test/resources/io/bootique/flyway/verifyInfoMessage.yml delete mode 100644 bootique-flyway5/src/test/resources/path/migration/V1__Init.sql diff --git a/bootique-flyway/pom.xml b/bootique-flyway/pom.xml index 526cba3..56a2116 100644 --- a/bootique-flyway/pom.xml +++ b/bootique-flyway/pom.xml @@ -37,6 +37,7 @@ 6.5.0 + 3.2.0 @@ -123,4 +124,22 @@ + + + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + + test-jar + + + + + + + diff --git a/bootique-flyway5/pom.xml b/bootique-flyway5/pom.xml index e25c7e5..0c4600e 100644 --- a/bootique-flyway5/pom.xml +++ b/bootique-flyway5/pom.xml @@ -61,6 +61,11 @@ slf4j-api compile + + io.bootique.flyway + bootique-flyway + ${project.parent.version} + @@ -98,6 +103,14 @@ bootique-logback test + + io.bootique.flyway + bootique-flyway + ${project.parent.version} + tests + test-jar + test + diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayFactory.java b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayFactory.java deleted file mode 100644 index ffe5988..0000000 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway; - -import io.bootique.annotation.BQConfig; -import io.bootique.annotation.BQConfigProperty; -import io.bootique.jdbc.DataSourceFactory; - -import javax.sql.DataSource; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.stream.Collectors; -import java.util.Map; -import java.util.HashMap; - -@BQConfig("Configures Flyway.") -public class FlywayFactory { - private List dataSources = new ArrayList(); - private List locations = Collections.singletonList("db/migration"); - private List configFiles = new ArrayList(); // list of config files to use - - FlywaySettings createDataSources(DataSourceFactory dataSourceFactory) { - final List dataSources = this.dataSources.stream().map(dataSourceFactory::forName).collect(Collectors.toList()); - return new FlywaySettings(dataSources, locations, configFiles); - } - - @BQConfigProperty("References to dataSources to access the database.") - public void setDataSources(List dataSources) { - this.dataSources = dataSources; - } - - @BQConfigProperty("The locations to scan recursively for migration scripts.") - public void setLocations(List locations) { - this.locations = locations; - } - - @BQConfigProperty("The list of Flyway configuration files to use.") - public void setConfigFiles(List configFiles) { - this.configFiles = configFiles; - } -} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModule.java b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModule.java deleted file mode 100644 index 6abd1a6..0000000 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModule.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway; - -import io.bootique.BQCoreModule; -import io.bootique.ConfigModule; -import io.bootique.config.ConfigurationFactory; -import io.bootique.di.Binder; -import io.bootique.di.Provides; -import io.bootique.flyway.command.BaselineCommand; -import io.bootique.flyway.command.CleanCommand; -import io.bootique.flyway.command.InfoCommand; -import io.bootique.flyway.command.MigrateCommand; -import io.bootique.flyway.command.RepairCommand; -import io.bootique.flyway.command.ValidateCommand; -import io.bootique.jdbc.DataSourceFactory; - -import static java.util.Arrays.asList; - -public class FlywayModule extends ConfigModule { - - @Override - public void configure(Binder binder) { - asList( - BaselineCommand.class, - CleanCommand.class, - InfoCommand.class, - MigrateCommand.class, - RepairCommand.class, - ValidateCommand.class - ).forEach(command -> BQCoreModule.extend(binder).addCommand(command)); - } - - @Provides - public FlywaySettings createFlywayDataSources(ConfigurationFactory configFactory, DataSourceFactory dataSourceFactory) { - return config(FlywayFactory.class, configFactory).createDataSources(dataSourceFactory); - } - - @Provides - public FlywayRunner createFlywayRunner(FlywaySettings flywaySettings) { - return new FlywayRunner(flywaySettings); - } -} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModuleProvider.java b/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModuleProvider.java deleted file mode 100644 index 1b056a6..0000000 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/FlywayModuleProvider.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway; - -import io.bootique.BQModuleMetadata; -import io.bootique.BQModuleProvider; -import io.bootique.di.BQModule; -import io.bootique.jdbc.JdbcModuleProvider; - -import java.lang.reflect.Type; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -public class FlywayModuleProvider implements BQModuleProvider { - - @Override - public BQModule module() { - return new FlywayModule(); - } - - @Override - public Map configs() { - return Collections.singletonMap("flyway", FlywayFactory.class); - } - - @Override - public Collection dependencies() { - return Collections.singletonList(new JdbcModuleProvider()); - } - - @Override - public BQModuleMetadata.Builder moduleBuilder() { - return BQModuleProvider.super - .moduleBuilder() - .description("Provides database migrations based on the Flyway library."); - } -} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/BaselineCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/BaselineCommand.java deleted file mode 100644 index abdbf55..0000000 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/command/BaselineCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway.command; - -import javax.inject.Inject; -import javax.inject.Provider; - -import io.bootique.cli.Cli; -import io.bootique.command.CommandOutcome; -import io.bootique.command.CommandWithMetadata; -import io.bootique.flyway.FlywayRunner; -import io.bootique.meta.application.CommandMetadata; - -import static io.bootique.flyway.command.FlywayCommand.command; - -public class BaselineCommand extends CommandWithMetadata { - private Provider runnerProvider; - - @Inject - public BaselineCommand(Provider runnerProvider) { - super(CommandMetadata - .builder(BaselineCommand.class) - .description("Baselines an existing database, " + - "excluding all migrations up to and including baselineVersion.") - .build()); - this.runnerProvider = runnerProvider; - } - - @Override - public CommandOutcome run(Cli cli) { - return command(() -> runnerProvider.get().baseline()); - } -} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/CleanCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/CleanCommand.java deleted file mode 100644 index 5936c07..0000000 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/command/CleanCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway.command; - -import javax.inject.Inject; -import javax.inject.Provider; - -import io.bootique.cli.Cli; -import io.bootique.command.CommandOutcome; -import io.bootique.command.CommandWithMetadata; -import io.bootique.flyway.FlywayRunner; -import io.bootique.meta.application.CommandMetadata; - -import static io.bootique.flyway.command.FlywayCommand.command; - -public class CleanCommand extends CommandWithMetadata { - private Provider runnerProvider; - - @Inject - public CleanCommand(Provider runnerProvider) { - super(CommandMetadata - .builder(CleanCommand.class) - .description("Drops all objects (tables, views, procedures, triggers, ...) in the configured schemas." + - "The schemas are cleaned in the order specified by the schemas property.") - .build()); - this.runnerProvider = runnerProvider; - } - - @Override - public CommandOutcome run(Cli cli) { - return command(() -> runnerProvider.get().clean()); - } -} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/FlywayCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/FlywayCommand.java deleted file mode 100644 index d5be9f5..0000000 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/command/FlywayCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway.command; - -import io.bootique.command.CommandOutcome; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@FunctionalInterface -interface FlywayCommand { - Logger LOGGER = LoggerFactory.getLogger(FlywayCommand.class); - - /** - * SAM for passing operations inside command method. - */ - void apply() throws Exception; - - static CommandOutcome command(FlywayCommand command) { - try { - command.apply(); - return CommandOutcome.succeeded(); - } catch (Exception e) { - LOGGER.error("Error while executing command.", e); - return CommandOutcome.failed(1, e.getMessage()); - } - } -} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/InfoCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/InfoCommand.java deleted file mode 100644 index af2a06a..0000000 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/command/InfoCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway.command; - -import javax.inject.Inject; -import javax.inject.Provider; - -import io.bootique.cli.Cli; -import io.bootique.command.CommandOutcome; -import io.bootique.command.CommandWithMetadata; -import io.bootique.flyway.FlywayRunner; -import io.bootique.meta.application.CommandMetadata; - -import static io.bootique.flyway.command.FlywayCommand.command; - -public class InfoCommand extends CommandWithMetadata { - private Provider runnerProvider; - - @Inject - public InfoCommand(Provider runnerProvider) { - super(CommandMetadata - .builder(InfoCommand.class) - .description("Prints the details and status information about all the migrations.") - .build()); - this.runnerProvider = runnerProvider; - } - - @Override - public CommandOutcome run(Cli cli) { - return command(() -> runnerProvider.get().info()); - } -} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/MigrateCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/MigrateCommand.java deleted file mode 100644 index 3fbbfb6..0000000 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/command/MigrateCommand.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway.command; - -import javax.inject.Inject; -import javax.inject.Provider; - -import io.bootique.cli.Cli; -import io.bootique.command.CommandOutcome; -import io.bootique.command.CommandWithMetadata; -import io.bootique.flyway.FlywayRunner; -import io.bootique.meta.application.CommandMetadata; - -import static io.bootique.flyway.command.FlywayCommand.command; - -public class MigrateCommand extends CommandWithMetadata { - private Provider runnerProvider; - - @Inject - public MigrateCommand(Provider runnerProvider) { - super(CommandMetadata - .builder(MigrateCommand.class) - .description("Migrates the schema to the latest version. " + - "Flyway will create the metadata table automatically if it doesn't exist.") - .build()); - this.runnerProvider = runnerProvider; - } - - @Override - public CommandOutcome run(Cli cli) { - return command(() -> runnerProvider.get().migrate()); - } -} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/RepairCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/RepairCommand.java deleted file mode 100644 index 7798c5c..0000000 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/command/RepairCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway.command; - -import javax.inject.Inject; -import javax.inject.Provider; - -import io.bootique.cli.Cli; -import io.bootique.command.CommandOutcome; -import io.bootique.command.CommandWithMetadata; -import io.bootique.flyway.FlywayRunner; -import io.bootique.meta.application.CommandMetadata; - -import static io.bootique.flyway.command.FlywayCommand.command; - -public class RepairCommand extends CommandWithMetadata { - private Provider runnerProvider; - - @Inject - public RepairCommand(Provider runnerProvider) { - super(CommandMetadata - .builder(RepairCommand.class) - .description("Repairs the metadata table.") - .build()); - this.runnerProvider = runnerProvider; - } - - @Override - public CommandOutcome run(Cli cli) { - return command(() -> runnerProvider.get().repair()); - } -} diff --git a/bootique-flyway5/src/main/java/io/bootique/flyway/command/ValidateCommand.java b/bootique-flyway5/src/main/java/io/bootique/flyway/command/ValidateCommand.java deleted file mode 100644 index d7bcf31..0000000 --- a/bootique-flyway5/src/main/java/io/bootique/flyway/command/ValidateCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway.command; - -import javax.inject.Inject; -import javax.inject.Provider; - -import io.bootique.cli.Cli; -import io.bootique.command.CommandOutcome; -import io.bootique.command.CommandWithMetadata; -import io.bootique.flyway.FlywayRunner; -import io.bootique.meta.application.CommandMetadata; - -import static io.bootique.flyway.command.FlywayCommand.command; - -public class ValidateCommand extends CommandWithMetadata { - private Provider runnerProvider; - - @Inject - public ValidateCommand(Provider runnerProvider) { - super(CommandMetadata - .builder(ValidateCommand.class) - .description("Validate applied migrations against resolved ones " + - "(on the filesystem or classpath) to detect accidental " + - "changes that may prevent the schema(s) from being recreated exactly.") - .build()); - this.runnerProvider = runnerProvider; - } - - @Override - public CommandOutcome run(Cli cli) { - return command(() -> runnerProvider.get().validate()); - } -} diff --git a/bootique-flyway5/src/main/resources/META-INF/services/io.bootique.BQModuleProvider b/bootique-flyway5/src/main/resources/META-INF/services/io.bootique.BQModuleProvider deleted file mode 100644 index 98cbb48..0000000 --- a/bootique-flyway5/src/main/resources/META-INF/services/io.bootique.BQModuleProvider +++ /dev/null @@ -1 +0,0 @@ -io.bootique.flyway.FlywayModuleProvider \ No newline at end of file diff --git a/bootique-flyway5/src/test/java/io/bootique/flyway/FlywayModuleProviderIT.java b/bootique-flyway5/src/test/java/io/bootique/flyway/FlywayModuleProviderIT.java deleted file mode 100644 index 34b817b..0000000 --- a/bootique-flyway5/src/test/java/io/bootique/flyway/FlywayModuleProviderIT.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway; - -import io.bootique.BQRuntime; -import io.bootique.jdbc.JdbcModule; -import io.bootique.test.junit.BQModuleProviderChecker; -import io.bootique.test.junit.BQRuntimeChecker; -import io.bootique.test.junit.BQTestFactory; -import org.junit.Rule; -import org.junit.Test; - -public class FlywayModuleProviderIT { - - @Rule - public BQTestFactory testFactory = new BQTestFactory(); - - @Test - public void testAutoLoadable() { - BQModuleProviderChecker.testAutoLoadable(FlywayModuleProvider.class); - } - - @Test - public void testModuleDeclaresDependencies() { - final BQRuntime bqRuntime = testFactory.app().moduleProvider(new FlywayModuleProvider()).createRuntime(); - BQRuntimeChecker.testModulesLoaded(bqRuntime, JdbcModule.class, FlywayModule.class); - } -} diff --git a/bootique-flyway5/src/test/java/io/bootique/flyway/InfoTest.java b/bootique-flyway5/src/test/java/io/bootique/flyway/InfoTest.java deleted file mode 100644 index a3c0dc8..0000000 --- a/bootique-flyway5/src/test/java/io/bootique/flyway/InfoTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway; - -import io.bootique.BQRuntime; -import io.bootique.command.CommandOutcome; -import io.bootique.test.junit.BQTestFactory; -import org.junit.Rule; -import org.junit.Test; - -import java.util.Scanner; -import java.io.File; -import java.io.FileNotFoundException; - -import static org.junit.Assert.assertTrue; - -/** - * Tests for info command. - * - * @author Gert-Jan Paulissen - */ -public class InfoTest { - - @Rule - public final BQTestFactory testFactory = new BQTestFactory(); - - @Test - public void verifyInfoMessage() { - BQRuntime runtime; - - testFactory - .app("--config=classpath:io/bootique/flyway/verifyInfoMessage.yml", "--clean") - .autoLoadModules() - .run(); - - runtime = testFactory - .app("--config=classpath:io/bootique/flyway/verifyInfoMessage.yml", "--info") - .autoLoadModules() - .createRuntime(); - - testInfoCommand(runtime, 1); - - testFactory - .app("--config=classpath:io/bootique/flyway/verifyInfoMessage.yml", "--migrate") - .autoLoadModules() - .run(); - - runtime = testFactory - .app("--config=classpath:io/bootique/flyway/verifyInfoMessage.yml", "--info") - .autoLoadModules() - .createRuntime(); - - testInfoCommand(runtime, 2); - } - - private void testInfoCommand(BQRuntime runtime, int which) { - CommandOutcome result = runtime.run(); - assertTrue(result.isSuccess()); - - if (which == 1) { - assertTrue(textFoundInLogFile("+-----------+---------+--------------+------+--------------+---------+")); - assertTrue(textFoundInLogFile("| Category | Version | Description | Type | Installed On | State |")); - assertTrue(textFoundInLogFile("+-----------+---------+--------------+------+--------------+---------+")); - assertTrue(textFoundInLogFile("| Versioned | 1 | Init | SQL | | Pending |")); - assertTrue(textFoundInLogFile("| Versioned | 2 | Update table | JDBC | | Pending |")); - assertTrue(textFoundInLogFile("+-----------+---------+--------------+------+--------------+---------+")); - } else { - assertTrue(textFoundInLogFile("+-----------+---------+--------------+------+---------------------+---------+")); - assertTrue(textFoundInLogFile("| Category | Version | Description | Type | Installed On | State |")); - assertTrue(textFoundInLogFile("+-----------+---------+--------------+------+---------------------+---------+")); - assertTrue(textFoundInLogFile("| Versioned | 1 | Init | SQL | .......... ........ | Success |")); - assertTrue(textFoundInLogFile("| Versioned | 2 | Update table | JDBC | .......... ........ | Success |")); - assertTrue(textFoundInLogFile("+-----------+---------+--------------+------+---------------------+---------+")); - } - } - - private boolean textFoundInLogFile(String text) { - try { - Scanner scanner = new Scanner(new File("target/test.log")); - String pattern = text.replace("+", "\\+").replace("|", "\\|"); - - //now read the file line by line... - while (scanner.hasNextLine()) { - if (scanner.nextLine().matches("^.*" + pattern + "$")) - { - return true; - } - } - - } catch(FileNotFoundException e) { - return false; - } - - return false; - } -} diff --git a/bootique-flyway5/src/test/java/io/bootique/flyway/MigrateTest.java b/bootique-flyway5/src/test/java/io/bootique/flyway/MigrateTest.java deleted file mode 100644 index f840d3b..0000000 --- a/bootique-flyway5/src/test/java/io/bootique/flyway/MigrateTest.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Licensed to ObjectStyle LLC under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ObjectStyle LLC licenses - * this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package io.bootique.flyway; - -import io.bootique.BQRuntime; -import io.bootique.command.CommandOutcome; -import io.bootique.jdbc.test.DatabaseChannel; -import io.bootique.jdbc.test.Table; -import io.bootique.test.junit.BQTestFactory; -import org.junit.Rule; -import org.junit.Test; - -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -/** - * Tests for migrate command. - * - * @author Ibragimov Ruslan - */ -public class MigrateTest { - - @Rule - public final BQTestFactory testFactory = new BQTestFactory(); - - @Test - public void defaultMigration() { - BQRuntime runtime = testFactory - .app("--config=classpath:io/bootique/flyway/defaultMigration.yml", "--migrate") - .autoLoadModules() - .createRuntime(); - - testMigrateCommand(runtime); - } - - @Test - public void explicitDefaultMigration() { - BQRuntime runtime = testFactory - .app("--config=classpath:io/bootique/flyway/explicitDefaultMigration.yml", "--migrate") - .autoLoadModules() - .createRuntime(); - - testMigrateCommand(runtime); - } - - @Test - public void explicitNonDefaultMigration() { - BQRuntime runtime = testFactory - .app("--config=classpath:io/bootique/flyway/explicitNonDefaultMigration.yml", "--migrate") - .autoLoadModules() - .createRuntime(); - - testMigrateCommand(runtime); - } - - @Test - public void explicitNonDefaultMigrationConfigfile() { - BQRuntime runtime = testFactory - .app("--config=classpath:io/bootique/flyway/explicitNonDefaultMigrationConfigfile.yml", "--migrate") - .autoLoadModules() - .createRuntime(); - - testMigrateCommand(runtime); - } - - private void testMigrateCommand(BQRuntime runtime) { - CommandOutcome result = runtime.run(); - assertTrue(result.isSuccess()); - - Table a = DatabaseChannel.get(runtime).newTable("TEST").columnNames("ID", "NAME").build(); - List row = a.select(); - assertEquals(1, row.get(0)[0]); - assertEquals("Test", row.get(0)[1]); - assertEquals(2, row.get(1)[0]); - assertEquals("Test 2", row.get(1)[1]); - - a.matcher().assertMatches(2); - } -} diff --git a/bootique-flyway5/src/test/resources/db/migration/V1__Init.sql b/bootique-flyway5/src/test/resources/db/migration/V1__Init.sql deleted file mode 100644 index 31d7916..0000000 --- a/bootique-flyway5/src/test/resources/db/migration/V1__Init.sql +++ /dev/null @@ -1,21 +0,0 @@ ---Licensed to ObjectStyle LLC under one ---or more contributor license agreements. See the NOTICE file ---distributed with this work for additional information ---regarding copyright ownership. The ObjectStyle LLC licenses ---this file to you under the Apache License, Version 2.0 (the ---"License"); you may not use this file except in compliance ---with the License. You may obtain a copy of the License at --- http://www.apache.org/licenses/LICENSE-2.0 ---Unless required by applicable law or agreed to in writing, ---software distributed under the License is distributed on an ---"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ---KIND, either express or implied. See the License for the ---specific language governing permissions and limitations ---under the License. - -CREATE TABLE TEST ( - ID INT PRIMARY KEY, - NAME VARCHAR(255) -); - -INSERT INTO TEST VALUES (1, 'Test'); \ No newline at end of file diff --git a/bootique-flyway5/src/test/resources/io/bootique/flyway/defaultMigration.yml b/bootique-flyway5/src/test/resources/io/bootique/flyway/defaultMigration.yml deleted file mode 100644 index 34c2dee..0000000 --- a/bootique-flyway5/src/test/resources/io/bootique/flyway/defaultMigration.yml +++ /dev/null @@ -1,25 +0,0 @@ -# Licensed to ObjectStyle LLC under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ObjectStyle LLC licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -jdbc: - test: - url: jdbc:h2:mem:defaultMigration - username: '' - password: '' - driverClassName: org.h2.Driver - -flyway: - dataSources: - - test \ No newline at end of file diff --git a/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitDefaultMigration.yml b/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitDefaultMigration.yml deleted file mode 100644 index 71e2681..0000000 --- a/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitDefaultMigration.yml +++ /dev/null @@ -1,27 +0,0 @@ -# Licensed to ObjectStyle LLC under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ObjectStyle LLC licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -jdbc: - test: - url: jdbc:h2:mem:defaultMigration - username: '' - password: '' - driverClassName: org.h2.Driver - -flyway: - locations: - - db/migration - dataSources: - - test \ No newline at end of file diff --git a/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigration.yml b/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigration.yml deleted file mode 100644 index 55fabe1..0000000 --- a/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigration.yml +++ /dev/null @@ -1,27 +0,0 @@ -# Licensed to ObjectStyle LLC under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ObjectStyle LLC licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -jdbc: - test: - url: jdbc:h2:mem:defaultMigration - username: '' - password: '' - driverClassName: org.h2.Driver - -flyway: - locations: - - path/migration - dataSources: - - test \ No newline at end of file diff --git a/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.conf b/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.conf deleted file mode 100644 index cdfc237..0000000 --- a/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.conf +++ /dev/null @@ -1 +0,0 @@ -flyway.locations = path/migration diff --git a/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.yml b/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.yml deleted file mode 100644 index 756faf4..0000000 --- a/bootique-flyway5/src/test/resources/io/bootique/flyway/explicitNonDefaultMigrationConfigfile.yml +++ /dev/null @@ -1,29 +0,0 @@ -# Licensed to ObjectStyle LLC under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ObjectStyle LLC licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -jdbc: - test: - url: jdbc:h2:mem:defaultMigration - username: bogus - password: bogus - driverClassName: org.h2.Driver - -flyway: - locations: - - bogus - configFiles: - - classpath:io/bootique/flyway/explicitNonDefaultMigrationConfigfile.conf - dataSources: - - test diff --git a/bootique-flyway5/src/test/resources/io/bootique/flyway/verifyInfoMessage.yml b/bootique-flyway5/src/test/resources/io/bootique/flyway/verifyInfoMessage.yml deleted file mode 100644 index c2509ea..0000000 --- a/bootique-flyway5/src/test/resources/io/bootique/flyway/verifyInfoMessage.yml +++ /dev/null @@ -1,38 +0,0 @@ -# Licensed to ObjectStyle LLC under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ObjectStyle LLC licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -jdbc: - test: - url: jdbc:h2:mem:defaultMigration - username: '' - password: '' - driverClassName: org.h2.Driver - -flyway: - dataSources: - - test - -log: - level: warn - loggers: - io.bootique.flyway: - level: info - appenderRefs: - - test - appenders: - - type: file - name: test - logFormat: '%c{20}: %m%n' - file: target/test.log diff --git a/bootique-flyway5/src/test/resources/path/migration/V1__Init.sql b/bootique-flyway5/src/test/resources/path/migration/V1__Init.sql deleted file mode 100644 index 31d7916..0000000 --- a/bootique-flyway5/src/test/resources/path/migration/V1__Init.sql +++ /dev/null @@ -1,21 +0,0 @@ ---Licensed to ObjectStyle LLC under one ---or more contributor license agreements. See the NOTICE file ---distributed with this work for additional information ---regarding copyright ownership. The ObjectStyle LLC licenses ---this file to you under the Apache License, Version 2.0 (the ---"License"); you may not use this file except in compliance ---with the License. You may obtain a copy of the License at --- http://www.apache.org/licenses/LICENSE-2.0 ---Unless required by applicable law or agreed to in writing, ---software distributed under the License is distributed on an ---"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ---KIND, either express or implied. See the License for the ---specific language governing permissions and limitations ---under the License. - -CREATE TABLE TEST ( - ID INT PRIMARY KEY, - NAME VARCHAR(255) -); - -INSERT INTO TEST VALUES (1, 'Test'); \ No newline at end of file From bddbca675056c7d1a048b2d94c34e169ca529642 Mon Sep 17 00:00:00 2001 From: Gert-Jan Paulissen Date: Fri, 4 Sep 2020 12:22:26 +0200 Subject: [PATCH 6/8] Move flyway 6 version back to parent. --- bootique-flyway/pom.xml | 1 - pom.xml | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bootique-flyway/pom.xml b/bootique-flyway/pom.xml index 56a2116..b2c94b6 100644 --- a/bootique-flyway/pom.xml +++ b/bootique-flyway/pom.xml @@ -36,7 +36,6 @@ - 6.5.0 3.2.0 diff --git a/pom.xml b/pom.xml index 7037490..7a857dc 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,7 @@ ${project.version} + 6.5.5 1.4.200 From 46470d5c51ab0c403b45cd550c9d5928fe2b3144 Mon Sep 17 00:00:00 2001 From: Gert-Jan Paulissen Date: Fri, 4 Sep 2020 12:43:59 +0200 Subject: [PATCH 7/8] Using the bootique/bootique-flyway snapshot version. --- bootique-flyway5/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootique-flyway5/pom.xml b/bootique-flyway5/pom.xml index 0c4600e..a452b8f 100644 --- a/bootique-flyway5/pom.xml +++ b/bootique-flyway5/pom.xml @@ -24,7 +24,7 @@ io.bootique.flyway bootique-flyway-parent - 2.0-SNAPSHOT + 2.0.B1-SNAPSHOT bootique-flyway5 From 14d9571f6bdf46448c00da1d7f697d96efed48dc Mon Sep 17 00:00:00 2001 From: Gert-Jan Paulissen Date: Fri, 4 Sep 2020 14:38:46 +0200 Subject: [PATCH 8/8] Added showing the test log after failure. --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index da98449..1dde844 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,3 +36,13 @@ env: global: - secure: "t/DJwSV2TUQ2OxZBqDhWl1noCYqJkWGngSvcWMct5z4gcuNScg5Pw5ylBzNCl43lF045X9nOJdY40uH2UyNd1nwNW1XNehuJCgijU3rFX1xl/7rAq52B4FpECQhrwwzInpa5um/84Uwl61GghKqyFbxyGuxq7jzFSQl1vPmBuRdbKkkufr5APcIu5Ger9b1E7T9Crkcpv/u624T2Zz8Hxb8ezemAOK8fW9rTGLx044bjhCpubXoeYXdIuzKd0LxK5pop4ozoGZ5/L3DVB5JhXMrXi99Gjf+BPdiLTCChenU6H6kaqP//lOYRseRsn7kMT1i9zt5lfmn3udFgTekRjSDcz9YFwls/OjAo7rT0i8g7Rq68DiNJKojcKTB7Pp5j+PNVXru+QljvY/oFAfkWBUukKLemNALli2taStaXlfvRHeb+d5AnCPalwwOfNm6nkQJzkDxTxD6UlGj4IzTYQ1oxoAxkw7AIxKu9yp6zTgYX0OXHaioAdnpVYFUq9nIMUWVts957DVNHMTAbjXchyaG9Gsv8gE0iQN7hURhWnmrS+bQnWVlhrUYuIyavbDXVvHSzycEU59PNfGUFK+x7XujhWosmE6kHbSgJxZAF4SGxzCJpxOqrJTWjgYKgPwZ4yg2OFiQ04u8umqsFxHjvh02e9iG3OAA2l9F0L5A6jA8=" - secure: "CdB/iOvwr1UmoFn762u2vgru4J7Hyn+YO0KjWooe6k0VD6TNm7HIWYXyGSH/J3chO5BdzYv2TxnWFHaeTMq+84+MIBp/TfV3UfSX8pMuspvfqFtNcj7l2HCt9WJ95t4zvwyJjSR5lN6C2LIGrkztkx65uPi6SXqJUJnswMwjeftFfChTh05JprdZ5V8T/ArJzGLmy+EgqaNYR2lwtYUNf8MudTZgri9vVkECeO2c+V0/ELW5/+L/Qb1XnLcubPvMVfrxhuer8+YjLTDusjnIj9iwuLU5+kZM7uoAJDqLKHSSvruEtz2lMLNooEnINkJanNiRvpkfHLojJz0dAebdiuU47yz4Qpg1XFPGHwjDJvO0uL+C+DwGmKZ3kuWug+d6/5HtAcsSntdHxQhG0CoN48k7GkITTAdiTLmnzG+FBmUHswFP8bFZr24srMOuzWzCRr+xsKp93XWDHY+I93FnsBIEwWkqWjuwQUuEDv/6CGxRrdTk1Q8z/b6Ex/973cKFXRUnhwjQ2cBo+bScfRmUaMJBYSbY1yVGMDCyRtcpTClnhlzuQbXNVHxRMvREidRZkqM0C+LcERfHVzMaQ2QatYw1F0WCFSl8J5gjDNMwtHz0GU9t5gvLr7hogk2Jl8baBEI3LvkbANNz/mLP2oid4bZQmkmw9krQFZc/esLWFMI=" + +# to be able to see where it goes wrong (see also https://github.com/travis-ci/travis-ci/issues/6018) +after_failure: + - echo == Begin of test log(s) == + - for f in $(find . -name test.log); do echo "test log: $f"; cat $f; sleep 1; done + - echo == End of test log(s) == + +# give some time to spool the output +after_script: + - sleep 1