This is a SBT plugin that provides an interface to the Flyway database migration tool (http://flywaydb.org). The plugin is entirely self-contained and does not require previous installation of Flyway to operate. It is compatible with SBT 0.11.3+ and Scala 2.9.1+
The current version of the plugin is 1.2.
-
Add flyway-sbt-plugin to your
project/plugins.sbt
:resolvers += "sean8223 Releases" at "https://github.com/sean8223/repository/raw/master/releases" addSbtPlugin("sean8223" %% "flyway-sbt-plugin" % CURRENT_PLUGIN_VERSION) // see above
-
In your
build.sbt
, do the following:-
Inject the plugin settings into your build definition:
seq(flywaySettings:_*)
-
Add your database driver to your list of libraryDependencies with "flyway" scope:
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.22" % "flyway"
-
Configure options for your environment:
flywayOptions := Map("driver" -> "com.mysql.jdbc.Driver", "url" -> "jdbc:mysql://localhost:3306/foo", "user" -> "root", ...)
-
-
Test your configuration by running
flyway:info
from the SBT prompt.
The plugin exposes three settings:
-
flyway-options (
flywayOptions
in build.sbt): aMap[String, String]
containing configuration properties for Flyway. Refer to http://flywaydb.org/documentation/commandline/ for a full description of the values that can be passed into this Map. Note that the keys of this Map correspond to the the option name without the "flyway." prefix, e.g. "user" or "cleanOnValidationError". -
flyway-migration-directories (
flywayMigrationDirectories
in build.sbt): aSeq[File]
containing roots on the classpath that contain migrations SQL and/or Java. By default, these are set to the value ofcompile:resource-directory
(usually src/main/resources) andcompile:class-directory
(usually target/scala-version/sbt-version/classes), but can be changed to suit your project layout as needed. -
flyway-version (
flywayVersion
in build.sbt): aString
indicating the version of Flyway to use. The default value is "2.0.3". This plugin has not been tested extensively with other versions, YMMV.
If you need to make additional libraries available to Flyway, simply add
them to libraryDependencies
under the "flyway" scope.
All tasks from the command tool are supported:
-
flyway:init: Creates and initializes the metadata table in the schema.
-
flyway:clean: Drops all objects in the schema without dropping the schema itself.
-
flyway:migrate: Migrates the schema to the latest version. Flyway will create the metadata table automatically if it doesn't exist.
-
flyway:validate: Validates the applied migrations against the ones available on the classpath. The build fails if differences in migration names, types or checksums are found.
-
flyway:info: Prints the details and status information about all the migrations.
-
flyway:repair: Repairs the Flyway metadata table after a failed migration. User objects left behind must still be cleaned up manually.
- 1.0: Initial release
- 1.1: Changed name of setting keys to avoid namespace conflicts
- 1.2: Removed dependencies on compile, added additional classpaths to flyway to prevent ClassNotFoundExceptions when searching for Java migrations