-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: update createdAt and updatedAt fields to store timestamps in UTC #155
Conversation
server/db/schema.ts
Outdated
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow().notNull(), | ||
updatedAt: timestamp('updated_at', { withTimezone: true }).defaultNow().notNull(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need timezone, convert it to client's time zone on client-side. Keep default timezone to UTC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{withTimezone: true}
takes care that the timestamp stored in DB is in UTC format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
understood, did some research. give me some time to merge.
Question: what will happen to existing dates? which are already in database?
As per my research, data will still be the same, it's just postgres
will assume they are in UTC. However, since server is in us-east, i.e. UTC−05:00 current timestamps are stored in that format. Now how do we deal with this? Will we have to write a seed which retrieves time, converts to UTC and saves it back?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per debugging, current timestamps are saved in UTC, so no need for seed.
Final resolution: timestamps are already stored in UTC. So we won't be storing timezone, rather, we will be converting them to client timezone in client side. We will use some date library to do this. |
Feature Title[Follow conventional title. See: https://www.conventionalcommits.org/en/v1.0.0/]
Type of Change
Describe your changes
[A brief overview of the feature being added. Explain the functionality and its intended purpose.]
Screenshots/Videos (if applicable)
[Attach screenshots or videos demonstrating the new feature in action.]
Loom Video: loom
Checklist