SBT Plugin

This is the official Flyway database migration plugin for Scala's sbt.

Supported SBT Versions

  • SBT 1.0.0 and newer

Installation

Add the following line to your plugins.sbt file:
addSbtPlugin("io.github.davidmweber" % "flyway-sbt" % "5.0.0-RC2")

Tasks

Name Description
flywayMigrate Migrates the database
flywayClean Drops all objects in the configured schemas
flywayInfo Prints the details and status information about all the migrations
flywayValidate Validates the applied migrations against the ones available on the classpath
flywayBaseline Baselines an existing database, excluding all migrations up to and including baselineVersion
flywayRepair Repairs the metadata table
flywayInfo Prints information about the migration

Configuration

The Flyway SBT plugin can be configured in the following ways:

Directly in build.sbt

enablePlugins(FlywayPlugin)
    
flywayUrl := "jdbc:hsqldb:file:target/flyway_sample;shutdown=true"
flywayUser := "SA"
flywayLocations += "org.flywaydb.sample.migration"
flywaySchemas := Seq("schema1", "schema2", "schema3")
flywayPlaceholders := Map(
    "keyABC" -> "valueXYZ",
    "otherplaceholder" -> "value123"
)

Through System properties

> sbt -Dflyway.user=myUser -Dflyway.schemas=schema1,schema2 -Dflyway.placeholders.keyABC=valXYZ

Overriding order

System properties override Plugin configuration

Custom Configurations

The flywayBaseSettings value of the Flyway plugin provides base configuration and task definitions for the plugin. This can be reused in custom configurations other than the those provided for the runtime and test configurations, if projects require it. These settings may be reused as follows:

enablePlugins(FlywayPlugin)

lazy val CustomConfig = config("custom") describedAs "A custom config." extend Runtime

lazy val customSettings: Seq[Def.Setting[_]] = Seq(
  flywayUser := "customUser",
  flywayPassword := "customPassword",
  flywayUrl := "jdbc:driver://host:port/db",
   ...
)

lazy val app = (project in file("app")).
  settings(inConfig(CustomConfig)(FlywayPlugin.flywayBaseSettings(CustomConfig) ++ customSettings): _*)

SBT: migrate