Topic Change : Slick Schema Code Generation
In this session, we discuss the use of code generation to remove the pain of writing out Slick database schema when working with or evolving an existing database schema. We'll demo a plugin that, with only a few lines of configuration, enables:
generation of tagged id types for primary and foreign keys
restricting schema generation to specific tables
separation of row and table specifications into distinct compilation units
customizable mappings between application and database types
This work arises from real-world experience working with Slick and legacy database schemas. The feelings of safety of having a database schema described in Scala are sometimes dwarfed by the pain of actually having to write and maintain the Scala mappings. This becomes obvious when building a new project with an existing database.
The code generation component is bundled with Slick. However, the documentation and default implementation show only the most trivial use-case and require a more complecated build. With every new project we have updated and expanded on the use-cases the plugin covers. Now, we would like to share what we have built and learned.