Skip to content

Commit

Permalink
Feature/validate migration naming (#86)
Browse files Browse the repository at this point in the history
* introduced validateMigrationNaming setting key
* test the new validation
* cleanup
* update plugin to latest version
* fix plugin.sbt
* format
  • Loading branch information
smiklos authored Nov 10, 2024
1 parent 602ff35 commit 12efd61
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/main/scala/flywaysbt/FlywayPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
// *********************
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -288,7 +295,8 @@ object FlywayPlugin extends AutoPlugin {
flywayTarget.value,
flywayOutOfOrder.value,
flywayCallbacks.value,
flywaySkipDefaultCallbacks.value
flywaySkipDefaultCallbacks.value,
flywayValidateMigrationNaming.value
),
flywayConfigSqlMigration := ConfigSqlMigration(
flywaySqlMigrationPrefix.value,
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/sbt-test/flyway-sbt/test5/build.sbt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions src/sbt-test/flyway-sbt/test5/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 3 additions & 0 deletions src/sbt-test/flyway-sbt/test5/src/main/hello.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Main extends App {
println("Hello")
}
Original file line number Diff line number Diff line change
@@ -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)
);
3 changes: 3 additions & 0 deletions src/sbt-test/flyway-sbt/test5/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Check that neither info nor migrate works if there are incorrectly named migrations
-> flywayInfo
-> flywayMigrate

0 comments on commit 12efd61

Please sign in to comment.