From da1e7ad34a8b71c09e566e513773a03a1c07e694 Mon Sep 17 00:00:00 2001 From: Dave Kichler Date: Wed, 13 Sep 2023 10:00:09 -0400 Subject: [PATCH 1/3] feat: Upgrading Flyway dependencies to 9.22.0. Updating sbt to 1.9.3 while we're at it. --- build.sbt | 4 +-- project/build.properties | 2 +- .../io/github/davidmweber/FlywayPlugin.scala | 30 ++++++++++++------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/build.sbt b/build.sbt index ee871ce..779bf42 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,5 @@ -val flywayVersion = "7.4.0" -val pluginVersion = "7.4.0" +val flywayVersion = "9.22.0" +val pluginVersion = "9.22.0" lazy val root = (project in file (".")) .enablePlugins(SbtPlugin) diff --git a/project/build.properties b/project/build.properties index 9b83df9..af71419 100644 --- a/project/build.properties +++ b/project/build.properties @@ -14,4 +14,4 @@ # limitations under the License. # -sbt.version=1.4.4 +sbt.version=1.9.3 diff --git a/src/main/scala/io/github/davidmweber/FlywayPlugin.scala b/src/main/scala/io/github/davidmweber/FlywayPlugin.scala index 573fa73..d2ab5d5 100644 --- a/src/main/scala/io/github/davidmweber/FlywayPlugin.scala +++ b/src/main/scala/io/github/davidmweber/FlywayPlugin.scala @@ -16,16 +16,17 @@ package io.github.davidmweber import java.util.Properties - import org.flywaydb.core.Flyway import org.flywaydb.core.api.callback.Callback import org.flywaydb.core.api.logging.{Log, LogCreator, LogFactory} import org.flywaydb.core.internal.info.MigrationInfoDumper -import sbt.Keys._ -import sbt._ +import sbt.Keys.* +import sbt.* -import scala.collection.JavaConverters._ +import scala.collection.JavaConverters.* import org.flywaydb.core.api.configuration.FluentConfiguration +import org.flywaydb.core.api.pattern.ValidatePattern +import org.flywaydb.core.internal.util.ValidatePatternUtils object FlywayPlugin extends AutoPlugin { @@ -109,7 +110,14 @@ object FlywayPlugin extends AutoPlugin { callbacks: Seq[Callback], skipDefaultCallbacks: Boolean) private case class ConfigSqlMigration(sqlMigrationPrefix: String, repeatableSqlMigrationPrefix: String, sqlMigrationSeparator: String, sqlMigrationSuffixes: String*) private case class ConfigMigrate(ignoreMissingMigrations: Boolean, ignoreFutureMigrations: Boolean, ignoreFailedMigrations: Boolean, - baselineOnMigrate: Boolean, validateOnMigrate: Boolean, mixed: Boolean, group: Boolean, installedBy: String) + baselineOnMigrate: Boolean, validateOnMigrate: Boolean, mixed: Boolean, group: Boolean, installedBy: String) { + def ignorePatterns: Seq[ValidatePattern] = { + var patterns = Seq.empty[String] + if (ignoreMissingMigrations) patterns = patterns :+ "*:missing" + if (ignoreFailedMigrations || ignoreFutureMigrations) patterns = patterns :+ "*:future" + patterns.map(ValidatePattern.fromPattern) + } + } private case class ConfigPlaceholder(placeholderReplacement: Boolean, placeholders: Map[String, String], placeholderPrefix: String, placeholderSuffix: String) private case class Config(dataSource: ConfigDataSource, base: ConfigBase, migrationLoading: ConfigMigrationLoading, @@ -154,9 +162,9 @@ object FlywayPlugin extends AutoPlugin { flywayOutOfOrder := defaults.isOutOfOrder, flywayCallbacks := new Array[Callback](0), flywaySkipDefaultCallbacks := defaults.isSkipDefaultCallbacks, - flywayIgnoreMissingMigrations := defaults.isIgnoreMissingMigrations, - flywayIgnoreFutureMigrations := defaults.isIgnoreFutureMigrations, - flywayIgnoreFailedFutureMigration := defaults.isIgnoreFutureMigrations, + flywayIgnoreMissingMigrations := ValidatePatternUtils.isMissingIgnored(defaults.getIgnoreMigrationPatterns), + flywayIgnoreFutureMigrations := ValidatePatternUtils.isFutureIgnored(defaults.getIgnoreMigrationPatterns), + flywayIgnoreFailedFutureMigration := ValidatePatternUtils.isFutureIgnored(defaults.getIgnoreMigrationPatterns), flywayPlaceholderReplacement := defaults.isPlaceholderReplacement, flywayPlaceholders := defaults.getPlaceholders.asScala.toMap, flywayPlaceholderPrefix := defaults.getPlaceholderPrefix, @@ -277,11 +285,9 @@ object FlywayPlugin extends AutoPlugin { .sqlMigrationSuffixes(config.sqlMigrationSuffixes: _*) } def configure(config: ConfigMigrate): FluentConfiguration = { - val ignoreFutureMigrations = if(config.ignoreFailedMigrations) true else config.ignoreFutureMigrations flyway - .ignoreMissingMigrations(config.ignoreMissingMigrations) - .ignoreFutureMigrations(ignoreFutureMigrations) + .ignoreMigrationPatterns(config.ignorePatterns:_*) .baselineOnMigrate(config.baselineOnMigrate) .validateOnMigrate(config.validateOnMigrate) .mixed(config.mixed) @@ -316,6 +322,8 @@ object FlywayPlugin extends AutoPlugin { def warn(message: String): Unit = { streams foreach (_.log.warn(message)) } def error(message: String): Unit = { streams foreach (_.log.error(message)) } def error(message: String, e: Exception): Unit = { streams foreach (_.log.error(message)); streams foreach (_.log.trace(e)) } + + def notice(message: String): Unit = { streams foreach (_.log.info(message)) } } } From 8466a5c3d2c565677e596a7680a6e0320dbb984a Mon Sep 17 00:00:00 2001 From: Dave Kichler Date: Wed, 13 Sep 2023 10:59:08 -0400 Subject: [PATCH 2/3] feat: Adjusting config default and test cases to account for the change in default clean disabled configuration property (changed in Flyway 9.0.0) --- src/main/scala/io/github/davidmweber/FlywayPlugin.scala | 2 +- src/sbt-test/flyway-sbt/test1/build.sbt | 2 ++ src/sbt-test/flyway-sbt/test2/build.sbt | 2 ++ src/sbt-test/flyway-sbt/test3/build.sbt | 4 +++- src/sbt-test/flyway-sbt/test4/build.sbt | 2 ++ 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/scala/io/github/davidmweber/FlywayPlugin.scala b/src/main/scala/io/github/davidmweber/FlywayPlugin.scala index d2ab5d5..f140ca9 100644 --- a/src/main/scala/io/github/davidmweber/FlywayPlugin.scala +++ b/src/main/scala/io/github/davidmweber/FlywayPlugin.scala @@ -59,7 +59,7 @@ object FlywayPlugin extends AutoPlugin { val flywaySqlMigrationSeparator = settingKey[String]("The file name separator for Sql migrations (default: __)") val flywaySqlMigrationSuffixes = settingKey[Seq[String]]("The file name suffixes for Sql migrations (default: .sql)") val flywayCleanOnValidationError = settingKey[Boolean]("Whether to automatically call clean or not when a validation error occurs. (default: {@code false})
This is exclusively intended as a convenience for development. Even tough we strongly recommend not to change migration scripts once they have been checked into SCM and run, this provides a way of dealing with this case in a smooth manner. The database will be wiped clean automatically, ensuring that the next migration will bring you back to the state checked into SCM. Warning ! Do not enable in production !") - val flywayCleanDisabled = settingKey[Boolean]("Whether to disable clean. This is especially useful for production environments where running clean can be quite a career limiting move. (default: false)") + val flywayCleanDisabled = settingKey[Boolean]("Whether to disable clean. This is especially useful for production environments where running clean can be quite a career limiting move. (default: true)") val flywayTarget = settingKey[String]("The target version up to which Flyway should run migrations. Migrations with a higher version number will not be applied. (default: the latest version)") val flywayOutOfOrder = settingKey[Boolean]("Allows migrations to be run \"out of order\" (default: {@code false}). If you already have versions 1 and 3 applied, and now a version 2 is found, it will be applied too instead of being ignored.") val flywayCallbacks = settingKey[Seq[Callback]]("A list of callbacks that will be used for Flyway lifecycle notifications. (default: Empty)") diff --git a/src/sbt-test/flyway-sbt/test1/build.sbt b/src/sbt-test/flyway-sbt/test1/build.sbt index 4bce500..f1c425d 100644 --- a/src/sbt-test/flyway-sbt/test1/build.sbt +++ b/src/sbt-test/flyway-sbt/test1/build.sbt @@ -11,3 +11,5 @@ flywayUser := "SA" flywayLocations += "db/sbt" flywayUrl in Test := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true" flywayUser in Test := "SA" +flywayCleanDisabled := false +Test / flywayCleanDisabled := false diff --git a/src/sbt-test/flyway-sbt/test2/build.sbt b/src/sbt-test/flyway-sbt/test2/build.sbt index 4441402..bae8075 100644 --- a/src/sbt-test/flyway-sbt/test2/build.sbt +++ b/src/sbt-test/flyway-sbt/test2/build.sbt @@ -11,3 +11,5 @@ flywayUser := "SA" flywayLocations += "db/migration" flywayUrl in Test := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true" flywayUser in Test := "SA" +flywayCleanDisabled := false +Test / flywayCleanDisabled := false diff --git a/src/sbt-test/flyway-sbt/test3/build.sbt b/src/sbt-test/flyway-sbt/test3/build.sbt index 975436b..384bb88 100644 --- a/src/sbt-test/flyway-sbt/test3/build.sbt +++ b/src/sbt-test/flyway-sbt/test3/build.sbt @@ -11,4 +11,6 @@ flywayUser := "SA" flywayLocations := Seq("filesystem:src/main/resources/db/migration") flywayUrl in Test := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true" flywayUser in Test := "SA" -flywayLocations in Test := Seq("filesystem:src/main/resources/db/migration") \ No newline at end of file +flywayLocations in Test := Seq("filesystem:src/main/resources/db/migration") +flywayCleanDisabled := false +Test / flywayCleanDisabled := false diff --git a/src/sbt-test/flyway-sbt/test4/build.sbt b/src/sbt-test/flyway-sbt/test4/build.sbt index 7eebed8..b3beb7a 100644 --- a/src/sbt-test/flyway-sbt/test4/build.sbt +++ b/src/sbt-test/flyway-sbt/test4/build.sbt @@ -9,3 +9,5 @@ libraryDependencies ++= Seq( flywayUrl := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true" flywayUser := "SA" flywayCallbacks := Seq(Callback) +flywayCleanDisabled := false +Test / flywayCleanDisabled := false From 5d7fcb4e2f2f0909f8550e3077c33dc4f996012f Mon Sep 17 00:00:00 2001 From: Dave Kichler Date: Wed, 13 Sep 2023 11:01:42 -0400 Subject: [PATCH 3/3] fix: Flyway ends up modifying the placeholders map in some of it's core library, ensure the type provided is mutable/supports put --- src/main/scala/io/github/davidmweber/FlywayPlugin.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/io/github/davidmweber/FlywayPlugin.scala b/src/main/scala/io/github/davidmweber/FlywayPlugin.scala index f140ca9..b6f3e2d 100644 --- a/src/main/scala/io/github/davidmweber/FlywayPlugin.scala +++ b/src/main/scala/io/github/davidmweber/FlywayPlugin.scala @@ -297,7 +297,7 @@ object FlywayPlugin extends AutoPlugin { def configure(config: ConfigPlaceholder): FluentConfiguration = { flyway .placeholderReplacement(config.placeholderReplacement) - .placeholders(config.placeholders.asJava) + .placeholders(new java.util.HashMap(config.placeholders.asJava)) .placeholderPrefix(config.placeholderPrefix) .placeholderSuffix(config.placeholderSuffix) }