Skip to content
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

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

Closed
egoist opened this issue Apr 15, 2024 · 5 comments
Closed

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

egoist opened this issue Apr 15, 2024 · 5 comments
Labels
bug Something isn't working drizzle-kit

Comments

@egoist
Copy link

egoist commented Apr 15, 2024

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 egoist added the bug Something isn't working label Apr 15, 2024
@JohnGemstone
Copy link

JohnGemstone commented Apr 15, 2024

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:

const precision = this.precision === undefined ? '' : ` (${this.precision})`;

If you compare the function to PgTimestampString you can see there is no whitespace:

const precision = this.precision === undefined ? '' : `(${this.precision})`;

For a release, I guess this will need a deeper fix with the push logic to handle / ignore these discrepancies.

@nckre
Copy link

nckre commented Apr 24, 2024

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.

@novelnet
Copy link

Same issue here: #2210

@kengoldfarb
Copy link

Opened a PR w/ @JohnGemstone 's fix:
#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",

@AndriiSherman
Copy link
Member

Should be fixed in latest versions of drizzle-kit! Feel free to reopen if it's not fixed for you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working drizzle-kit
Projects
None yet
Development

No branches or pull requests

7 participants