117 lines
3.8 KiB
Scala
117 lines
3.8 KiB
Scala
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",
|
|
// "joda-time" % "joda-time" % "2.10.2",
|
|
// "org.joda" % "joda-convert" % "2.2.1",
|
|
"com.google.inject" % "guice" % "4.2.3"
|
|
)
|
|
|
|
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"
|
|
)
|
|
javacOptions in ThisBuild ++= Seq("-source", "1.8", "-target", "1.8")
|
|
|
|
lazy val flyway = (project in file("modules/flyway"))
|
|
.enablePlugins(FlywayPlugin)
|
|
.settings(
|
|
libraryDependencies += "org.flywaydb" % "flyway-core" % FlywayVersion,
|
|
flywayLocations := Seq("classpath:db/migration"),
|
|
flywayUrl := databaseUrl,
|
|
flywayUser := databaseUser,
|
|
flywayPassword := databasePassword,
|
|
flywayBaselineOnMigrate := true
|
|
)
|
|
|
|
lazy val api = (project in file("modules/api")).settings(
|
|
libraryDependencies ++= Seq(
|
|
"com.typesafe.play" %% "play-json" % "2.8.1",
|
|
),
|
|
)
|
|
|
|
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",
|
|
"io.scalaland" %% "chimney" % "0.5.2"
|
|
// "com.github.tototoshi" %% "slick-joda-mapper" % "2.4.1"
|
|
),
|
|
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 code =
|
|
// "import com.github.tototoshi.slick.H2JodaSupport._\n" + "import org.joda.time.DateTime\n" + super.code
|
|
|
|
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,
|
|
"com.typesafe.play" %% "play-slick" % "5.0.0",
|
|
"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)
|
|
// fork := true
|