Skip to content

Commit

Permalink
Merge pull request #91 from dkichler/version-upgrade
Browse files Browse the repository at this point in the history
Bare minimum to support adoption of Flyway 9.22.0
  • Loading branch information
davidmweber authored Feb 5, 2024
2 parents 7fc35d2 + 5d7fcb4 commit 7bea2da
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# limitations under the License.
#

sbt.version=1.4.4
sbt.version=1.9.3
34 changes: 21 additions & 13 deletions src/main/scala/io/github/davidmweber/FlywayPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -58,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})<br/> 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)")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -291,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)
}
Expand All @@ -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)) }
}
}

2 changes: 2 additions & 0 deletions src/sbt-test/flyway-sbt/test1/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/sbt-test/flyway-sbt/test2/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/sbt-test/flyway-sbt/test3/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
flywayLocations in Test := Seq("filesystem:src/main/resources/db/migration")
flywayCleanDisabled := false
Test / flywayCleanDisabled := false
2 changes: 2 additions & 0 deletions src/sbt-test/flyway-sbt/test4/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7bea2da

Please sign in to comment.