Most of my database table models have inserted_at and updated_at timestamp fields which must be updated on creation and update events respectively. Is it possible to do this in a most DRY and transparent way in Slick. These audit columns are also not required in my Table projection (*
) and is only used for auditing and debugging. One option was to use custom Sqltype like below.
val insertedAt = column[Timestamp]("inserted_at", O.SqlType("TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP"))
val updatedAt = column[Timestamp]("updated_at", O.SqlType("TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
But the above code is database specific and H2 doesn't support it.