lastland / scala-forklift

Type-safe data migration tool for Slick, Git and beyond.
Other
188 stars 31 forks source link

Overriding of Slick Code generation #18

Closed krivachy closed 8 years ago

krivachy commented 8 years ago

I would like to use Joda DateTimes in the Slick generated models. It supports this via overriding the SourceCodeGenerator, here's an example: https://github.com/tminglei/slick-pg/blob/master/examples/codegen-customization/codegen/src/main/scala/demo/CustomizedCodeGenerator.scala#L43

Is it possible to override/configure this?

lastland commented 8 years ago

Yes. It is possible, but probably not very convenient in current version.

You can override the SourceCodeGenerator by overriding https://github.com/lastland/scala-forklift/blob/develop/migrations/slick/src/main/scala/Codegen.scala#L24-L64. You can find Forklift is overriding SourceCodeGenerator in L43. The starting template offers a place to override the code generator (https://github.com/lastland/scala-forklift-start-template/blob/master/migrations/src/main/scala/Codegen.scala).

Unfortunately, when overriding this method, you need to copy a bunch of code from the original method which is not related to SourceCodeGenerator.

I'm gonna refactor this part tonight to make it more modular, and publish the changes in 0.2.2-SNAPSHOT. You can probably wait a little bit if you don't mind using the SNAPSHOT version? Will keep you updated in this thread.

krivachy commented 8 years ago

Cool! Yes, I see I could have overridden it, sorry should have looked around a bit more.

lastland commented 8 years ago

Don't worry. Good use case. It makes me realize that this part of code is not so convenient to override. :smiley:

lastland commented 8 years ago

Hi, I have just published 0.2.2-SNAPSHOT. In the latest version you can simply override the getGenerator method to get what you want. See: https://github.com/lastland/scala-forklift/blob/develop/migrations/slick/src/main/scala/Codegen.scala#L33-L46

Of course the old method of overriding genCode still works.

krivachy commented 8 years ago

Thanks, I'll give it a go!