3

Did anyone succeed in using Slick (I am currently using 3.0.0-RC3, the latest available version) to generate a table definition containing DB-specific functions? If so, how to achieve that?

Example: I have a column in Postgres with the following definition:

"request_date" timestamp default now(),

which I tried (unsuccessfully) describe in Slick DDL.

First attempt:

def requestDate = column[Option[DateTime]]("request_date", O Default "now()")

Of course, this was rejected:

[error] <path-to-file>: type mismatch;
[error]  found   : String("now()")
[error]  required: Option[org.joda.time.DateTime]
[error]     def requestDate = column[Option[DateTime]]("request_date", O Default "now()")

OK, I have tried to define a SimpleFunction (I already have DateTime converter in place):

val dbNow = SimpleFunction.nullary[DateTime]("now")
def requestDate = column[Option[DateTime]]("request_date", O Default dbNow)

which produced another error:

[error] <path-to-file>: type mismatch;
[error]  found   : slick.lifted.Rep[org.joda.time.DateTime]
[error]  required: Option[org.joda.time.DateTime]
[error]     def requestDate = column[Option[DateTime]]("request_date", O Default dbNow)

I have also tried SimpleLiteral[DateTime]("now()"), which resulted in a similar error. (Removing Option did not help either).

Any ideas would be appreciated. It is a bit frustrating that such a simple thing does not seem to be easily available...

Ashalynd
  • 12,363
  • 2
  • 34
  • 37

1 Answers1

0

Currently not supported: https://github.com/slick/slick/issues/214 . You need to alter your table accordingly using plain SQL

cvogt
  • 11,260
  • 30
  • 46
  • I see. Thanks for the link - really old issue there, doesn't look like it's going to be solved soon. Sigh. – Ashalynd Apr 16 '15 at 05:20
  • 1
    Generating the DDL from Slick Table classes isn't necessarily a good idea anyways. You can only do it once. Migrations need to happen in SQL. Why not do schema stuff in SQL from the start, including the initial DDL and use code generation instead? – cvogt Apr 16 '15 at 19:45
  • We do it actually. (using flywaydb). This was more out-of-curiosity question. – Ashalynd Apr 16 '15 at 22:43