= Flyway
:page-aliases: Plugin_Flyway.adoc

Enables you to configure and run https://flywaydb.org/[Flyway] commands from your mill build file.
The flyway module currently supports the most common flyway use cases with file based migrations.

Configure flyway by overriding settings in your module. For example

.`build.mill`
[source,scala]
----
//| mvnDeps: ["com.lihaoyi::mill-contrib-flyway:$MILL_VERSION"]
package build

import mill.*, scalalib.*

import contrib.flyway.FlywayModule

object foo extends ScalaModule with FlywayModule {
  def scalaVersion = "2.12.8"

  //region flyway
  def flywayUrl = "jdbc:postgresql:myDb" // required
  def flywayDriverDeps = Seq(mvn"org.postgresql:postgresql:42.2.5") // required
  def flywayUser = "postgres" // optional
  // def flywayPassword = "" // optional
  //endregion
}
----

Flyway will look for migration files in `db/migration` in all resources folders by default.
This should work regardless of if you are using a mill or sbt project layout.

You can then run common flyway commands like

[source,console]
----
> mill foo.flywayClean
> mill foo.flywayInfo
> mill foo.flywayMigrate
----
 if you want to use this plugin with mysql database, make sure to add `org.flywaydb:flyway-mysql:11.20.1` extra dependency in the build file header
----

CAUTION: You should never hard-code credentials or check them into a version control system.
You should write some code to populate the settings for flyway instead.
For example `def flywayPassword = Task.Input(Task.ctx.env("FLYWAY_PASSWORD"))`
