sbt task to generate from schema only when absent

40 views
Skip to first unread message

Matthew Pocock

unread,
May 20, 2015, 10:02:54 AM5/20/15
to scala...@googlegroups.com
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

virtualeyes

unread,
May 21, 2015, 1:29:48 AM5/21/15
to scala...@googlegroups.com
How about creating a separate SBT task that you run manually? I do that as schema changes are known (maintain the db), but ymmv depending on situation.

Also, a minute for 50 tables? Takes 2-3 seconds here.

Christopher Vogt

unread,
May 28, 2015, 2:13:24 PM5/28/15
to scala...@googlegroups.com
I agree on your SBT comments. Contributions welcome :). I'd be happy to
review it but have no time to write it myself atm. The conditional
generation is more of an SBT question, why not write some code in your
build that checks src_managed? What I do: only call the codegen command
manually. Chris
> mailto: turingate...@gmail.com <mailto:turingate...@gmail.com>
>
> Integrative Bioinformatics Group, School of Computing Science, Newcastle
> University
> mailto: matthew...@ncl.ac.uk <mailto:matthew...@ncl.ac.uk>
>
> gchat: turingate...@gmail.com <mailto:turingate...@gmail.com>
> msn: matthew...@yahoo.co.uk <mailto:matthew...@yahoo.co.uk>
> irc.freenode.net <http://irc.freenode.net/>: drdozer
> skype: matthew.pocock
> tel: (0191) 2566550
> mob: +447535664143
>
> --
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Slick / ScalaQuery" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to scalaquery+...@googlegroups.com
> <mailto:scalaquery+...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/scalaquery/CAHQS_ewkSTqb7zaWF57Ex7hwPEGkK1To14sxvdVAEfy9bD-31Q%40mail.gmail.com
> <https://groups.google.com/d/msgid/scalaquery/CAHQS_ewkSTqb7zaWF57Ex7hwPEGkK1To14sxvdVAEfy9bD-31Q%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages