fix: ensure UTC session timezone in PrismaPg connections (#4285)#4321
fix: ensure UTC session timezone in PrismaPg connections (#4285)#4321sudoeren wants to merge 2 commits into
Conversation
) @prisma/adapter-pg's internal formatDateTime function converts JS Date objects to PostgreSQL TIMESTAMPTZ strings without appending a timezone offset. When the database session timezone is not UTC (e.g. UTC+8), PostgreSQL misinterprets the value, causing stored timestamps to be shifted backward. Fix by appending 'options=-c timezone=UTC' to the connection URL in all three places that create a PrismaPg adapter, ensuring every session interprets timezone-naive timestamp strings as UTC.
|
@sudoeren is attempting to deploy a commit to the Umami Software Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR fixes a session-timezone mismatch in
Confidence Score: 3/5Not safe to merge as-is: the seed script will fail to compile and crash at runtime due to a variable scoping mistake. The core fix in scripts/seed/index.ts — the Important Files Changed
Sequence DiagramsequenceDiagram
participant App
participant getClient
participant URL as URL Parser
participant PrismaPg
participant PG as PostgreSQL
App->>getClient: initialize client
getClient->>URL: new URL(DATABASE_URL)
URL-->>getClient: connectionUrl
getClient->>getClient: check existingOptions for 'timezone'
alt timezone not set
getClient->>connectionUrl: "set options=-c timezone=UTC"
end
getClient->>PrismaPg: "new PrismaPg({ connectionString })"
PrismaPg->>PG: "connect with options=-c timezone=UTC"
PG-->>PrismaPg: "session timezone = UTC"
PrismaPg-->>getClient: adapter ready
getClient->>App: PrismaClient with UTC session
|
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Summary
Fixes #4285
Root Cause
@prisma/adapter-pg's internal ormatDateTime function converts JavaScript Date objects to PostgreSQL TIMESTAMPTZ strings without appending a timezone offset. For example:
2024-01-15 10:30:00 ← no UTC offsetWhen the PostgreSQL session timezone is not UTC (e.g. UTC+8), the database interprets the timezone-naive string as being in the session timezone rather than UTC. This causes the stored timestamp to be shifted backward by the timezone offset.
Fix
Append options=-c timezone=UTC to the PostgreSQL connection URL in all three places that create a PrismaPg adapter:
This tells PostgreSQL to set the session timezone to UTC for every connection, ensuring timezone-naive TIMESTAMPTZ strings from the adapter are correctly interpreted as UTC.
Closes #4285
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.