Skip to content

Instantly share code, notes, and snippets.

@nightscape
Created June 19, 2018 11:34
Show Gist options
  • Save nightscape/3f25afa573424bb3de3cd4af6cf1b4f5 to your computer and use it in GitHub Desktop.
Save nightscape/3f25afa573424bb3de3cd4af6cf1b4f5 to your computer and use it in GitHub Desktop.
import ammonite.ops._
import mill._
import mill.util.Ctx
import mill.modules.Jvm
trait FlywayModule extends JavaModule {
def flywayMigrationPaths: T[Seq[PathRef]] = T { resources() }
def flywayUser: T[String]
def flywayPassword: T[String]
def flywayJdbcUrl: T[String]
def flywayJdbcDriverDeps: T[Agg[Dep]] = T { Agg.empty[Dep] }
def flywayVersion: T[String] = "5.1.1"
def flywayDeps: T[Agg[PathRef]] = T {
Lib.resolveDependencies(
repositories,
Lib.depToDependency(_, "2.12.4"),
Seq(
ivy"org.flywaydb:flyway-core:${flywayVersion()}",
ivy"org.flywaydb:flyway-commandline:${flywayVersion()}",
) ++ flywayJdbcDriverDeps()
)
}
def doMigrate(jdbcUrl: String, user: String, password: String, migrationPaths: Agg[Path], classpath: Agg[Path])(implicit ctx: Ctx): Unit = {
val args = s"migrate -jarDirs=${classpath.map(_ / up).mkString(",")} -url=$jdbcUrl -user=$user -password=$password -locations=${migrationPaths.map(f => s"filesystem:$f").mkString(",")}".split(" ")
Jvm.subprocess(
"org.flywaydb.commandline.Main",
classpath,
mainArgs = args)(ctx)
}
def migrate = T {
doMigrate(
flywayJdbcUrl(),
flywayUser(),
flywayPassword(),
flywayMigrationPaths().map(_.path),
flywayDeps().map(_.path))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment