drizzle-orm
drizzle-orm copied to clipboard
[BUG]: data loss when using timestamp(3) and `push` command
What version of drizzle-orm
are you using?
0.30.8
What version of drizzle-kit
are you using?
0.20.14
Describe the Bug
When I have the following in my table schema:
createdAt: timestamp("createdAt", { precision: 3 })
.notNull()
when I run drizzle-kit push:pg
drizzle-kit somehow thinks timestamp(3)
and timestamp (3)
are different and causing the table to be truncated:
Expected behavior
there shouldn't be data loss
Environment & setup
No response
I encountered this same issue too, my only 'hack' was to set mode to string:
createdAt: timestamp("created_at", {precision: 3, mode: 'string' })
.notNull(),
which outputs a timestamp(3)
sql query with no whitespace.
this isn't good because it requires manual management of timestamps and changes to application code.
EDIT: you can temporarily fix this by deleting the space in the template string on this line: https://github.com/drizzle-team/drizzle-orm/blob/4706ad1e347fd41494b67f76416d13bae6382bd4/drizzle-orm/src/pg-core/columns/timestamp.ts#L57
If you compare the function to PgTimestampString you can see there is no whitespace: https://github.com/drizzle-team/drizzle-orm/blob/4706ad1e347fd41494b67f76416d13bae6382bd4/drizzle-orm/src/pg-core/columns/timestamp.ts#L121
For a release, I guess this will need a deeper fix with the push logic to handle / ignore these discrepancies.
Having the same issue, this occurs with every single db:push
command (even when there was no change to timestamp).
Removing the precision
fixes it.
Same issue here: https://github.com/drizzle-team/drizzle-orm/issues/2210
Opened a PR w/ @JohnGemstone 's fix: https://github.com/drizzle-team/drizzle-orm/pull/2278
I've also pushed a fixed npm package that can be used temporarily (https://www.npmjs.com/package/@kengoldfarb/drizzle-orm):
"drizzle-orm": "npm:@kengoldfarb/drizzle-orm@^0.30.11",