Skip to content

Add Flyway 5 integration for Oracle 12.1 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 22 additions & 0 deletions bootique-flyway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
Provides Flyway integration with Bootique.
</description>

<properties>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
</properties>

<dependencies>
<!-- Compile dependencies -->
<dependency>
Expand Down Expand Up @@ -119,4 +123,22 @@
</build>
</profile>
</profiles>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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("");
Expand All @@ -90,6 +91,7 @@ private void forEach(Consumer<Flyway> 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);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DataSource> dataSources;
private final String[] locations;
private final String[] configFiles; // list of config files to use
Expand All @@ -55,19 +63,39 @@ public String[] getLocations() {
public java.util.Map<java.lang.String,java.lang.String> getProperties() {
Map<String, String> config = new HashMap<String, String>();

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());
config.putAll(ConfigUtils.loadConfigurationFromReader(reader));
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());

final Map<String, String> fileConfig = ConfigUtils.loadConfigurationFromReader(reader);

config.putAll(fileConfig);
dumpConfiguration(fileConfig, file);
} catch(IOException e) {
throw new FlywayException(errorMessage, e);
}
} catch(IOException e) {
throw new RuntimeException(e);
}

ConfigUtils.dumpConfiguration(config);
dumpConfiguration(config, "ALL");

return config;
}

/**
* 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<String, String> config, String resource) {
if (logger.isDebugEnabled()) {
logger.debug("Using configuration resource " + resource);
for (Map.Entry<String, String> entry : new TreeMap<>(config).entrySet()) {
logger.debug(entry.getKey() + " -> " + entry.getValue());
}
}
}
}
139 changes: 139 additions & 0 deletions bootique-flyway5/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.bootique.flyway</groupId>
<artifactId>bootique-flyway-parent</artifactId>
<version>2.0.B1-SNAPSHOT</version>
</parent>

<artifactId>bootique-flyway5</artifactId>
<packaging>jar</packaging>

<name>bootique-flyway: Flyway5 Integration with Bootique</name>
<description>
Provides Flyway5 integration with Bootique.
</description>

<properties>
<flyway.version>5.1.4</flyway.version> <!-- latest version that supports Oracle 12.1 -->
</properties>

<dependencies>
<!-- Compile dependencies -->
<dependency>
<groupId>io.bootique</groupId>
<artifactId>bootique</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.bootique.jdbc</groupId>
<artifactId>bootique-jdbc</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.bootique.flyway</groupId>
<artifactId>bootique-flyway</artifactId>
<version>${project.parent.version}</version>
</dependency>

<!-- Unit test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.bootique</groupId>
<artifactId>bootique-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.bootique.jdbc</groupId>
<artifactId>bootique-jdbc-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.bootique.jdbc</groupId>
<artifactId>bootique-jdbc-tomcat</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.bootique.logback</groupId>
<artifactId>bootique-logback</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.bootique.flyway</groupId>
<artifactId>bootique-flyway</artifactId>
<version>${project.parent.version}</version>
<classifier>tests</classifier>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>

<!-- Optional profile used to sign artifacts -->
<profiles>
<profile>
<id>gpg</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Loading