2020-05-16 10:10:23 +00:00
|
|
|
import com.github.tototoshi.sbt.slick.CodegenPlugin.autoImport.{
|
|
|
|
slickCodegenDatabasePassword,
|
|
|
|
slickCodegenDatabaseUrl,
|
|
|
|
slickCodegenJdbcDriver
|
|
|
|
}
|
|
|
|
import play.core.PlayVersion.{current => playVersion}
|
|
|
|
import _root_.slick.codegen.SourceCodeGenerator
|
|
|
|
import _root_.slick.{model => m}
|
|
|
|
|
|
|
|
lazy val databaseUrl = sys.env.getOrElse("DB_DEFAULT_URL", "jdbc:h2:./test")
|
|
|
|
lazy val databaseUser = sys.env.getOrElse("DB_DEFAULT_USER", "sa")
|
|
|
|
lazy val databasePassword = sys.env.getOrElse("DB_DEFAULT_PASSWORD", "")
|
|
|
|
|
|
|
|
val FlywayVersion = "6.2.2"
|
|
|
|
|
|
|
|
version in ThisBuild := "1.1-SNAPSHOT"
|
|
|
|
|
|
|
|
resolvers in ThisBuild += Resolver.sonatypeRepo("releases")
|
|
|
|
resolvers in ThisBuild += Resolver.sonatypeRepo("snapshots")
|
|
|
|
|
|
|
|
libraryDependencies in ThisBuild ++= Seq(
|
|
|
|
"javax.inject" % "javax.inject" % "1",
|
2020-08-22 10:48:11 +00:00
|
|
|
"com.google.inject" % "guice" % "4.2.3",
|
|
|
|
"org.flywaydb" %% "flyway-play" % "6.0.0"
|
2020-05-16 10:10:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
scalaVersion in ThisBuild := "2.13.1"
|
|
|
|
scalacOptions in ThisBuild ++= Seq(
|
|
|
|
"-encoding",
|
|
|
|
"UTF-8", // yes, this is 2 args
|
|
|
|
"-deprecation",
|
|
|
|
"-feature",
|
|
|
|
"-unchecked",
|
|
|
|
"-Xlint",
|
|
|
|
"-Ywarn-numeric-widen"
|
|
|
|
)
|
2020-08-22 10:48:11 +00:00
|
|
|
javacOptions in ThisBuild ++= Seq("-source", "11", "-target", "11")
|
2020-05-16 10:10:23 +00:00
|
|
|
|
|
|
|
lazy val flyway = (project in file("modules/flyway"))
|
|
|
|
.enablePlugins(FlywayPlugin)
|
|
|
|
.settings(
|
|
|
|
libraryDependencies += "org.flywaydb" % "flyway-core" % FlywayVersion,
|
2020-08-22 10:48:11 +00:00
|
|
|
flywayLocations := Seq("classpath:conf/db/migration/default"),
|
2020-05-16 10:10:23 +00:00
|
|
|
flywayUrl := databaseUrl,
|
|
|
|
flywayUser := databaseUser,
|
|
|
|
flywayPassword := databasePassword,
|
|
|
|
flywayBaselineOnMigrate := true
|
|
|
|
)
|
|
|
|
|
|
|
|
lazy val api = (project in file("modules/api")).settings(
|
|
|
|
libraryDependencies ++= Seq(
|
2020-08-22 10:48:11 +00:00
|
|
|
"com.typesafe.play" %% "play-json" % "2.8.1",
|
|
|
|
"org.typelevel" %% "cats-core" % "2.1.1",
|
|
|
|
"org.typelevel" %% "cats-effect" % "2.1.4",
|
|
|
|
"io.monix" %% "monix" % "3.2.2",
|
|
|
|
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.2",
|
|
|
|
"ch.qos.logback" % "logback-classic" % "1.2.3"
|
|
|
|
)
|
2020-05-16 10:10:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
lazy val slick = (project in file("modules/slick"))
|
|
|
|
.enablePlugins(CodegenPlugin)
|
|
|
|
.settings(
|
|
|
|
libraryDependencies ++= Seq(
|
|
|
|
"com.zaxxer" % "HikariCP" % "3.4.2",
|
|
|
|
"com.typesafe.slick" %% "slick" % "3.3.2",
|
|
|
|
"com.typesafe.slick" %% "slick-hikaricp" % "3.3.2",
|
|
|
|
"io.bfil" %% "automapper" % "0.7.0",
|
2020-08-22 10:48:11 +00:00
|
|
|
"io.scalaland" %% "chimney" % "0.5.2",
|
|
|
|
"org.typelevel" %% "cats-core" % "2.1.1",
|
|
|
|
"org.typelevel" %% "cats-effect" % "2.1.4",
|
|
|
|
"io.monix" %% "monix" % "3.2.2",
|
|
|
|
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.2",
|
|
|
|
"ch.qos.logback" % "logback-classic" % "1.2.3"
|
2020-05-16 10:10:23 +00:00
|
|
|
),
|
|
|
|
slickCodegenDatabaseUrl := databaseUrl,
|
|
|
|
slickCodegenDatabaseUser := databaseUser,
|
|
|
|
slickCodegenDatabasePassword := databasePassword,
|
|
|
|
slickCodegenDriver := _root_.slick.jdbc.H2Profile,
|
|
|
|
slickCodegenJdbcDriver := "org.h2.Driver",
|
|
|
|
slickCodegenOutputPackage := "com.example.user.slick",
|
|
|
|
slickCodegenExcludedTables := Seq("schema_version"),
|
|
|
|
slickCodegenCodeGenerator := { (model: m.Model) =>
|
|
|
|
new SourceCodeGenerator(model) {
|
|
|
|
override def Table = new Table(_) {
|
|
|
|
override def Column = new Column(_) {
|
|
|
|
override def rawType = model.tpe match {
|
|
|
|
case "java.sql.Timestamp" =>
|
|
|
|
"java.time.Instant" // kill j.s.Timestamp
|
|
|
|
case _ =>
|
|
|
|
super.rawType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
sourceGenerators in Compile += slickCodegen.taskValue
|
|
|
|
)
|
|
|
|
.aggregate(api)
|
|
|
|
.dependsOn(api)
|
|
|
|
|
|
|
|
lazy val root = (project in file("."))
|
|
|
|
.enablePlugins(PlayScala)
|
|
|
|
.settings(
|
|
|
|
name := """play-scala-isolated-slick-example""",
|
|
|
|
TwirlKeys.templateImports += "com.example.user.User",
|
|
|
|
libraryDependencies ++= Seq(
|
|
|
|
guice,
|
|
|
|
"com.h2database" % "h2" % "1.4.199",
|
|
|
|
ws % Test,
|
|
|
|
"org.flywaydb" % "flyway-core" % FlywayVersion % Test,
|
|
|
|
"org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test,
|
|
|
|
"com.typesafe.play" %% "play-json" % "2.8.1",
|
|
|
|
"io.bfil" %% "automapper" % "0.7.0"
|
|
|
|
),
|
|
|
|
fork in Test := true
|
|
|
|
)
|
|
|
|
.aggregate(slick)
|
|
|
|
.dependsOn(slick)
|
2020-08-22 10:48:11 +00:00
|
|
|
.dependsOn(flyway)
|