diff --git a/src/main/scala/flywaysbt/FlywayPlugin.scala b/src/main/scala/flywaysbt/FlywayPlugin.scala index 10671a5..9ef6111 100644 --- a/src/main/scala/flywaysbt/FlywayPlugin.scala +++ b/src/main/scala/flywaysbt/FlywayPlugin.scala @@ -90,6 +90,11 @@ object FlywayPlugin extends AutoPlugin { val flywaySkipDefaultCallbacks = settingKey[Boolean]("Whether default built-in callbacks should be skipped. (default: false)") + val flywayValidateMigrationNaming = + settingKey[Boolean]( + "Whether to ignore migration files whose names do not match the naming conventions. (default: false)" + ) + // ********************* // settings for migrate // ********************* @@ -172,7 +177,8 @@ object FlywayPlugin extends AutoPlugin { target: String, outOfOrder: Boolean, callbacks: Seq[Callback], - skipDefaultCallbacks: Boolean + skipDefaultCallbacks: Boolean, + validateMigrationNaming: Boolean ) private case class ConfigSqlMigration( sqlMigrationPrefix: String, @@ -252,6 +258,7 @@ object FlywayPlugin extends AutoPlugin { flywayOutOfOrder := defaults.isOutOfOrder, flywayCallbacks := Seq.empty[Callback], flywaySkipDefaultCallbacks := defaults.isSkipDefaultCallbacks, + flywayValidateMigrationNaming := defaults.isValidateMigrationNaming, flywayIgnoreMissingMigrations := ValidatePatternUtils.isMissingIgnored(defaults.getIgnoreMigrationPatterns), flywayIgnoreFutureMigrations := ValidatePatternUtils.isFutureIgnored(defaults.getIgnoreMigrationPatterns), flywayIgnoreFailedFutureMigration := ValidatePatternUtils.isFutureIgnored(defaults.getIgnoreMigrationPatterns), @@ -288,7 +295,8 @@ object FlywayPlugin extends AutoPlugin { flywayTarget.value, flywayOutOfOrder.value, flywayCallbacks.value, - flywaySkipDefaultCallbacks.value + flywaySkipDefaultCallbacks.value, + flywayValidateMigrationNaming.value ), flywayConfigSqlMigration := ConfigSqlMigration( flywaySqlMigrationPrefix.value, @@ -416,6 +424,7 @@ object FlywayPlugin extends AutoPlugin { .resolvers(config.resolvers: _*) .skipDefaultResolvers(config.skipDefaultResolvers) .skipDefaultCallbacks(config.skipDefaultCallbacks) + .validateMigrationNaming(config.validateMigrationNaming) } def configure(config: ConfigSqlMigration): FluentConfiguration = { flyway diff --git a/src/sbt-test/flyway-sbt/test5/build.sbt b/src/sbt-test/flyway-sbt/test5/build.sbt new file mode 100644 index 0000000..645656d --- /dev/null +++ b/src/sbt-test/flyway-sbt/test5/build.sbt @@ -0,0 +1,11 @@ +organization := "org.flywaydb" +enablePlugins(FlywayPlugin) +name := "flyway-sbt-test5" + +libraryDependencies ++= Seq( + "org.hsqldb" % "hsqldb" % "2.5.0" +) + +flywayUrl := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true" +flywayUser := "SA" +flywayValidateMigrationNaming := true diff --git a/src/sbt-test/flyway-sbt/test5/project/plugins.sbt b/src/sbt-test/flyway-sbt/test5/project/plugins.sbt new file mode 100644 index 0000000..1088043 --- /dev/null +++ b/src/sbt-test/flyway-sbt/test5/project/plugins.sbt @@ -0,0 +1,5 @@ +sys.props.get("plugin.version") match { + case Some(x) => addSbtPlugin("com.github.sbt" % "flyway-sbt" % x) + case _ => sys.error("""|The system property 'plugin.version' is not defined. + |Specify this property using the scriptedLaunchOpts -D.""".stripMargin) +} diff --git a/src/sbt-test/flyway-sbt/test5/src/main/hello.scala b/src/sbt-test/flyway-sbt/test5/src/main/hello.scala new file mode 100644 index 0000000..d1dd94a --- /dev/null +++ b/src/sbt-test/flyway-sbt/test5/src/main/hello.scala @@ -0,0 +1,3 @@ +object Main extends App { + println("Hello") +} diff --git a/src/sbt-test/flyway-sbt/test5/src/main/resources/db/migration/V1_invalid_naming.sql b/src/sbt-test/flyway-sbt/test5/src/main/resources/db/migration/V1_invalid_naming.sql new file mode 100644 index 0000000..898507e --- /dev/null +++ b/src/sbt-test/flyway-sbt/test5/src/main/resources/db/migration/V1_invalid_naming.sql @@ -0,0 +1,20 @@ +-- +-- Copyright 2010-2017 Boxfuse GmbH +-- +-- Licensed 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_user ( + name VARCHAR(25) NOT NULL, + PRIMARY KEY(name) +); \ No newline at end of file diff --git a/src/sbt-test/flyway-sbt/test5/test b/src/sbt-test/flyway-sbt/test5/test new file mode 100644 index 0000000..2636edc --- /dev/null +++ b/src/sbt-test/flyway-sbt/test5/test @@ -0,0 +1,3 @@ +# Check that neither info nor migrate works if there are incorrectly named migrations +-> flywayInfo +-> flywayMigrate