Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lazy val slickGenerate = taskKey[Seq[File]]("slick code generation from an existing database")
- slickGenerate := {
- import java.io.File
- val dbName = ""
- val userName = ""
- val password = ""
- val url = s"jdbc:mysql://localhost:3306/$dbName" // adapt as necessary to your system
- val jdbcDriver = "com.mysql.jdbc.Driver" // replace if not MySQL
- val slickDriver = "slick.driver.MySQLDriver" // replace if not MySQL
- val resultRelativeDir = "model" // directory to create output scala slick definitions at
- val targetPackageName = "com.cmp.model" // package name to give it
- val resultFilePath = s"$resultRelativeDir/$targetPackageName/Tables.scala" // override the name if you like
- val backupFilePath = s"$resultRelativeDir/$targetPackageName/Tables.scala.auto-backup" // override the name if you like
- val format = scala.Console.BLUE + scala.Console.BOLD
- println(format + s"Backing up existing slick mappings source to: file://${baseDirectory.value}/$backupFilePath")
- println(format + s"About to auto-generate slick mappings source from database schema at $url...")
- sbt.IO.copyFile(new File(resultFilePath), new File(backupFilePath))
- (runner in Compile).value.run("slick.codegen.SourceCodeGenerator", (dependencyClasspath in Compile).value.files, Array(slickDriver, jdbcDriver, url, resultRelativeDir, targetPackageName, userName, password), streams.value.log)
- println(format + s"Result: file://${baseDirectory.value}/$resultFilePath" + scala.Console.RESET)
- val diff = (s"diff -u $resultFilePath $backupFilePath" #| "colordiff").!!
- println(scala.Console.BLUE + s"Changes compared to previous output file, follow, if any.\n\n $diff")
- Seq(file(resultFilePath))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement