Hi,
I'm using the following sbt to generate scala schemas from relational databases.
lazy val slick = TaskKey[Seq[File]]("gen-tables")
def slickCodeGenTask(pkg: String,
usr: String,
pwd: String,
outTo: String) = (sourceManaged, dependencyClasspath in Compile, runner in Compile, streams) map { (dir, cp, r, s) =>
val outputDir = (dir / "slick")
val url = "jdbc:postgresql://localhost/chebi"
val jdbcDriver = "org.postgresql.Driver"
val slickDriver = "slick.driver.PostgresDriver"
toError(r.run("slick.codegen.SourceCodeGenerator", cp.files, Array(
slickDriver, jdbcDriver, url, outputDir.getPath, pkg, usr, pwd), s.log))
val fname = outputDir.getPath + outTo
unmanagedSourceDirectories in Compile += outputDir
Seq(file(fname))
}
...
sourceGenerators in Compile <+= slickCodeGenTask("uk.ac.ebi.chebi", "chebi", "chebi", "/uk/ac/ebi/chebi/Tables.scala")
This works fine for small schemas, but I've got one with 50+ tables, and it takes a minute or so to generate and then compile the code. This kills my "type, go to browser, reload" cycle.
How would I modify this so that the slick code generation task only runs when there's no code in the unmanaged source directory? My ideal pipeline would be that whenever I wanted to trigger a regeneration of the schema, I'd simply clean that project and it would notice there was no code, so generate it.
As a more general note, it would be nice to have this kind of sbt integration all nicely tied up with a bow as an sbt plugin. Slick has revolutionised how I work with RDBMSs, but the build configuration is still too magical and manual for me to recommend it to colleagues without me co-owning the code-bases.
Thanks,
Matthew
--
Dr Matthew Pocock
Turing ate my hamster LTD
Integrative Bioinformatics Group, School of Computing Science, Newcastle University
skype: matthew.pocock
tel: (0191) 2566550