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
21.44k stars 484 forks source link

[BUG]: TIMESTAMPS showing up incorrectly on drizzle studio. #2549

Open dyzhuu opened 4 days ago

dyzhuu commented 4 days ago

What version of drizzle-orm are you using?

0.30.7

What version of drizzle-kit are you using?

0.21.1

Describe the Bug

Drizzle studio shows an incorrect timestamp that is 13 hours behind the expected timestamp.

This is how the table is defined:

export const gameSessions = pgTable("gameSession", {
  id: serial("id").primaryKey(),
  gameSessionScheduleId: integer("gameSessionScheduleId").references(
    () => gameSessionSchedules.id,
    { onDelete: "set null" },
  ),
  bookingOpen: timestamp("bookingOpen", { mode: "date" }).notNull(),
  bookingClose: timestamp("bookingClose", { mode: "date" }).notNull(),
  date: date("date").unique().notNull(),
  startTime: time("startTime").notNull(),
  endTime: time("endTime").notNull(),
  locationName: text("locationName").notNull(),
  locationAddress: text("locationAddress").notNull(),
  capacity: integer("capacity").notNull(),
  casualCapacity: integer("casualCapacity").notNull(),
});

Expected behavior

Data returned from query (expected):

{
    "id": 135,
    "gameSessionScheduleId": null,
    "bookingOpen": "2024-10-30T20:00:00.000Z",
    "bookingClose": "2024-11-04T06:30:00.000Z",
    ...
}

Data shown on drizzle studio: image

Environment & setup

No response

JavanFriedel commented 1 day ago

I also had a similiar issue here, and I think it has to do with storing the time in UTC, and then drizzle-kit seams to assume that it is stored in your local time zone, and then converts it again to UTC, creating an offset.

I can compare these values using another database viewer like Dbeaver.

DBeaver: image

DrizzleKit: image

Actual Response from Drizzle ORM in Production (correct): image

This means Drizzle Kit is providing a different response than Drizzle ORM. I am using a postgres database in this case, with the date mode on.