This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository topia. See http://git.nuiton.org/topia.git commit 27b23d3f7e24ce0b20fc03e87d51c1f1553865ca Author: Brendan Le Ny <bleny@codelutin.com> Date: Mon Dec 1 15:32:14 2014 +0100 Update to flyway 3.1, change initVersion to baselineVersion according to Flyway new practice (fixes #3587) --- pom.xml | 2 +- .../nuiton/topia/flyway/TopiaFlywayService.java | 8 ++- .../topia/flyway/TopiaFlywayServiceImpl.java | 58 ++++++++++++---------- 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index fc60c8e..87b14b1 100644 --- a/pom.xml +++ b/pom.xml @@ -235,7 +235,7 @@ <!-- libs version --> <commonsLoggingVersion>1.2</commonsLoggingVersion> <eugeneVersion>2.13</eugeneVersion> - <flywayVersion>3.0</flywayVersion> + <flywayVersion>3.1</flywayVersion> <guavaVersion>18.0</guavaVersion> <h2Version>1.4.181</h2Version> <hamcrestVersion>1.3</hamcrestVersion> diff --git a/topia-service-flyway/src/main/java/org/nuiton/topia/flyway/TopiaFlywayService.java b/topia-service-flyway/src/main/java/org/nuiton/topia/flyway/TopiaFlywayService.java index 18091e4..6173cf7 100644 --- a/topia-service-flyway/src/main/java/org/nuiton/topia/flyway/TopiaFlywayService.java +++ b/topia-service-flyway/src/main/java/org/nuiton/topia/flyway/TopiaFlywayService.java @@ -34,11 +34,17 @@ import org.nuiton.topia.persistence.TopiaMigrationService; public interface TopiaFlywayService extends TopiaMigrationService { /** + * @deprecated use {@link #FLYWAY_BASELINE_VERSION} + */ + @Deprecated + public static final String FLYWAY_INIT_VERSION = "flyway.initVersion"; + + /** * If you want flyway to init with an already existing DB, you must use * this configuration and give, as value the version of the already * existing schema. */ - public static final String FLYWAY_INIT_VERSION = "flyway.initVersion"; + public static final String FLYWAY_BASELINE_VERSION = "flyway.baselineVersion"; /** * Tells ToPIA to set (or not) the Flyway's target version from the model version. Expected values are "true" or diff --git a/topia-service-flyway/src/main/java/org/nuiton/topia/flyway/TopiaFlywayServiceImpl.java b/topia-service-flyway/src/main/java/org/nuiton/topia/flyway/TopiaFlywayServiceImpl.java index dd48540..15acc9e 100644 --- a/topia-service-flyway/src/main/java/org/nuiton/topia/flyway/TopiaFlywayServiceImpl.java +++ b/topia-service-flyway/src/main/java/org/nuiton/topia/flyway/TopiaFlywayServiceImpl.java @@ -61,9 +61,9 @@ public class TopiaFlywayServiceImpl implements TopiaFlywayService { private static final Log log = LogFactory.getLog(TopiaFlywayServiceImpl.class); /** - * Value for {@link #FLYWAY_INIT_VERSION} configuration parameter. + * Value for {@link #FLYWAY_BASELINE_VERSION} configuration parameter. */ - protected String flywayInitVersion = null; + protected String flywayBaselineVersion = null; /** * Value for {@link #USE_MODEL_VERSION} configuration parameter. @@ -79,11 +79,19 @@ public class TopiaFlywayServiceImpl implements TopiaFlywayService { modelVersion = topiaApplicationContext.getModelVersion(); - // set flywayInitVersion if provided - if (serviceConfiguration.containsKey(FLYWAY_INIT_VERSION)) { - flywayInitVersion = serviceConfiguration.get(FLYWAY_INIT_VERSION); - if (StringUtils.isBlank(flywayInitVersion)) { - throw new IllegalArgumentException("'" + flywayInitVersion + "' must not be empty"); + // set flywayBaselineVersion if provided + if (serviceConfiguration.containsKey(FLYWAY_BASELINE_VERSION)) { + flywayBaselineVersion = serviceConfiguration.get(FLYWAY_BASELINE_VERSION); + if (StringUtils.isBlank(flywayBaselineVersion)) { + throw new IllegalArgumentException("'" + FLYWAY_BASELINE_VERSION + "' must not be empty"); + } + } else if (serviceConfiguration.containsKey(FLYWAY_INIT_VERSION)) { + if (log.isWarnEnabled()) { + log.warn(FLYWAY_INIT_VERSION + " is deprecated, use " + FLYWAY_BASELINE_VERSION + " instead"); + } + flywayBaselineVersion = serviceConfiguration.get(FLYWAY_INIT_VERSION); + if (StringUtils.isBlank(flywayBaselineVersion)) { + throw new IllegalArgumentException("'" + FLYWAY_INIT_VERSION + "' must not be empty"); } } @@ -199,18 +207,18 @@ public class TopiaFlywayServiceImpl implements TopiaFlywayService { @Override public void initOnCreateSchema() { - String initVersion; + String baselineVersion; if (useModelVersion) { // Use model version, flywayInitVersion should not be specified - Preconditions.checkState(Strings.isNullOrEmpty(flywayInitVersion), + Preconditions.checkState(Strings.isNullOrEmpty(flywayBaselineVersion), FLYWAY_INIT_VERSION + " is not not compatible with " + USE_MODEL_VERSION + "=true"); if (log.isInfoEnabled()) { log.info("Using model version: " + modelVersion); } - initVersion = modelVersion; + baselineVersion = modelVersion; } else { // Do not use model version. That means we have to "guess" which is minimal the model version from the available migration scripts @@ -219,19 +227,19 @@ public class TopiaFlywayServiceImpl implements TopiaFlywayService { if (ArrayUtils.isEmpty(allMigrations)) { // Check that flywayInitVersion is declared - Preconditions.checkState(!Strings.isNullOrEmpty(flywayInitVersion), - "No migration found and " + USE_MODEL_VERSION + "=false. You need to declare a " + FLYWAY_INIT_VERSION); + Preconditions.checkState(!Strings.isNullOrEmpty(flywayBaselineVersion), + "No migration found and " + USE_MODEL_VERSION + "=false. You need to declare a " + FLYWAY_BASELINE_VERSION); if (log.isInfoEnabled()) { - log.info("Using " + FLYWAY_INIT_VERSION + " version: " + flywayInitVersion); + log.info("Using " + FLYWAY_BASELINE_VERSION + " version: " + flywayBaselineVersion); } - initVersion = flywayInitVersion; + baselineVersion = flywayBaselineVersion; } else { // useModelVersion=false and some migrations found, flywayInitVersion should not be specified - Preconditions.checkState(Strings.isNullOrEmpty(flywayInitVersion), - "Migrations found with " + USE_MODEL_VERSION + "=false. " + FLYWAY_INIT_VERSION + " shouldn't be set"); + Preconditions.checkState(Strings.isNullOrEmpty(flywayBaselineVersion), + "Migrations found with " + USE_MODEL_VERSION + "=false. " + FLYWAY_BASELINE_VERSION + " shouldn't be set"); // TreeSet will sort the versions because MigrationInfo implements Comparable TreeSet<MigrationInfo> treeSet = Sets.newTreeSet(Arrays.asList(allMigrations)); @@ -243,25 +251,25 @@ public class TopiaFlywayServiceImpl implements TopiaFlywayService { if (log.isInfoEnabled()) { log.info("Using highest migration version found: " + version); } - initVersion = version; + baselineVersion = version; } } if (log.isInfoEnabled()) { - log.info("init flyway to version " + initVersion); + log.info("baseline flyway to version " + baselineVersion); } - flyway.setInitVersion(initVersion); - flyway.setInitDescription("schema creation called on application context by topia flyway service"); - flyway.init(); + flyway.setBaselineVersion(baselineVersion); + flyway.setBaselineDescription("schema creation called on application context by topia flyway service"); + flyway.baseline(); } @Override public void runSchemaMigration() { - if (flywayInitVersion == null) { + if (flywayBaselineVersion == null) { if (log.isDebugEnabled()) { log.debug("schema exists, no flywayInitVersion found, let suppose flyway is already initialized"); } @@ -275,10 +283,10 @@ public class TopiaFlywayServiceImpl implements TopiaFlywayService { } else { if (log.isDebugEnabled()) { - log.debug("schema exists, will ask flyway to init if necessary to version " + flywayInitVersion); + log.debug("schema exists, will ask flyway to init if necessary to version " + flywayBaselineVersion); } - flyway.setInitOnMigrate(true); - flyway.setInitVersion(flywayInitVersion); + flyway.setBaselineOnMigrate(true); + flyway.setBaselineVersion(flywayBaselineVersion); } if (useModelVersion) { -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.