I have an existing Vapor 3 application in production that has a fair bit of data stored in a PostgreSQL database. I'm currently in the process of upgrading from Vapor 3 to Vapor 4, and I note that the default .datetime type in Vapor 4 migrations is creating columns with a type of timestamp with time zone NOT NULL.
Vapor 3 used timestamp without time zone.
I'd really prefer not to have to migrate all of the CRUD timestamps to a new format if it's not necessary to. Is there a way to specify the format of my .datetime data in the migration/model?
In your Vapor 4 migration, use .custom(SQLRaw("TIMESTAMP WITHOUT TIME ZONE")) instead of .datetime. There is unfortunately no simpler way that I recall.
Thanks, Gwynne. That’s a reasonably contained workaround - do I need to do anything from the model side, or will it respect the format of the column?
I've just tried using the custom data type, and Fluent (or PostgreSQL) is decoding the dates incorrectly. I assume it's treating them as if they include the timezone.
I think I'm just going to need to manually migrate the column in my existing schema to use a timezone. That's okay, it appears to be less onerous than I had assumed.