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: [Drizzle] Convert MySQL timestamps to datetimes #1676
Comments
seems reasonable. do you want to open a pr for this? |
I'm watching the Drizzle issue which will introduce the change for the default timestamp, since I don't want to rely on semantics that are kind of undefined behavior (the on update logic being in the default statement) in code that will likely ship to production applications. Once that goes through, I will probably make a PR if no one else has. |
hey @Wundero this line updatedAt: datetime("updatedAt", { fsp: 3 }).default(sql`CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP`), throws this error when trying
[EDIT]: It does work, I was using timestamp instead of datetime as the column type lol |
Is your feature request related to a problem? Please describe.
For date + time related fields, MySQL's timestamp field is only 32 bits, and will run into issues once 2038 comes around. This isn't a giant issue per se, and users can certainly correct this on their own, but IMO there really is no harm in switching to datetime columns instead, since they can hold dates from
1000-01-01 00:00:00
to9999-12-31 23:59:59
, which will last a lot longer.Describe the solution you'd like to see
Prisma already stores datetimes like this (reference), and switching drizzle is as simple as:
This is using a sub-second precision of 3 points, which is in-line with what Prisma does, just for consistency.
Describe alternate solutions
N/A
Additional information
The syntax for
onUpdateCurrentTimestamp
requires drizzle-team/drizzle-orm#1114 to be merged, and I don't know that Drizzle currently supports the syntax necessary for auto-updates directly, though I believe you can just insert it into the default SQL like so:The text was updated successfully, but these errors were encountered: