drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[BUG]: data loss when using timestamp(3) and `push` command

Open egoist opened this issue 4 months ago • 4 comments

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:

CleanShot 2024-04-15 at 14 34 39@2x

Expected behavior

there shouldn't be data loss

Environment & setup

No response

egoist avatar Apr 15 '24 06:04 egoist

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.

JohnGemstone avatar Apr 15 '24 21:04 JohnGemstone

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.

nckre avatar Apr 24 '24 17:04 nckre

Same issue here: https://github.com/drizzle-team/drizzle-orm/issues/2210

novelnet avatar Apr 30 '24 13:04 novelnet

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",

kengoldfarb avatar May 08 '24 17:05 kengoldfarb