drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.72k stars 652 forks source link

[BUG]: DEFAULT now() with a time zone creates an invalid schema #3245

Open L-Mario564 opened 4 weeks ago

L-Mario564 commented 4 weeks ago

What version of drizzle-orm are you using?

?

What version of drizzle-kit are you using?

?

Describe the Bug

From drizzle-kit-mirror repo: https://github.com/drizzle-team/drizzle-kit-mirror/issues/33.

We have a table like this:

CleanShot 2023-04-10 at 15 29 47@2x

And it generates a schema like this:

export const timeoutLocks = pgTable("timeout_locks", {
  acquiredAt: timestamp("acquiredAt", { withTimezone: true, mode: 'string' })
        .default((now() AT TIME ZONE 'utc'::text)),
  id: uuid("id").notNull(),
},
(table) => {
  return {
      idKey: uniqueIndex("timeout_locks_id_key").on(table.id),
  }
});

With the line

        .default((now() AT TIME ZONE 'utc'::text)),

Being an issue - this is invalid JavaScript. Seems like there's special handling of default: now(), while other defaults get expressions with the sql helper, and this is stuck in the middle.

Expected behavior

No response

Environment & setup

No response

zhihengGet commented 4 days ago

any update ?