Rohan Sircar
cb9524eac7
Rewrote slick db service using monix task instead of future Added cats IO to controller to make use of above db service Added action methods that support effect wrappers other than future Added play-flyway to auto-manage migrations Moved migration files to appropriate directory as a result of above Added cors filter to work with separately hosted frontend Made logger log at debug
121 lines
4.0 KiB
Scala
121 lines
4.0 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",
|
|
"com.google.inject" % "guice" % "4.2.3",
|
|
"org.flywaydb" %% "flyway-play" % "6.0.0"
|
|
)
|
|
|
|
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", "11", "-target", "11")
|
|
|
|
lazy val flyway = (project in file("modules/flyway"))
|
|
.enablePlugins(FlywayPlugin)
|
|
.settings(
|
|
libraryDependencies += "org.flywaydb" % "flyway-core" % FlywayVersion,
|
|
flywayLocations := Seq("classpath:conf/db/migration/default"),
|
|
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",
|
|
"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"
|
|
)
|
|
)
|
|
|
|
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",
|
|
"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"
|
|
),
|
|
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)
|
|
.dependsOn(flyway)
|