Timestamp with time zone attribute in PostgreSQL Database
Given I use a postgres database and I want to add a "timestamp with time zone" attribute to a given WASP entity, what's the correct syntax?
entity JobAd {=psl
id Int @id @default(autoincrement())
description String
isDone Boolean @default(false)
user User? @relation(fields: [userId], references: [id])
userId Int?
creationTimestamp Timestamp with time zone @default(now())
psl=}
3 Replies
Hi @OrBlatt. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In Wasp, entities are defined using Prisma Schema Language (PSL). According to the provided knowledge sources, the
timestamp with time zone
data type is not explicitly mentioned. However, Prisma supports the DateTime
type, which can be used to store date and time values.
Here is how you can define a creationTimestamp
field with a default value of the current time:
In this case, DateTime
is used instead of Timestamp with time zone
. The @default(now())
directive sets the default value of creationTimestamp
to the current date and time.
Please note that while DateTime
does include time information, it does not include timezone information. If you need to store timezone information, you might need to store it in a separate field.
For more information on defining entities in Wasp, you can refer to the official documentation (https://wasp-lang.dev/docs/data-model/entities#defining-an-entity).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @OrBlatt, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?If I use DateTime attribute, will it be migrated from DateTime to Timestamp with time zone when I move from SQLite to PostgreSQL? I'm asking because PostgreSQL is mandatory for deployment.
If unsure, it is probably best to start with PosgreSQL right away! It is easy to run the database for development, you need Docker installed and can just do
wasp start db