[PR #3477] [CLOSED] fix(drizzle): use timestamp with time zone for PostgreSQL #4845

Closed
opened 2026-03-13 12:01:50 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/3477
Author: @JuanPabloGilA
Created: 7/19/2025
Status: Closed

Base: mainHead: feat/fix-timestamp-with-timezone


📝 Commits (5)

  • 57c146a fix(drizzle): use timestamp with time zone for PostgreSQL
  • a9b0fad chore: apply formatting with Biome
  • e3885ec Merge branch 'main' into feat/fix-timestamp-with-timezone
  • 9e363c5 remove no related files to the pr
  • 4629a99 change test state to idle

📊 Changes

3 files changed (+43 additions, -38 deletions)

View changed files

📝 packages/cli/src/generators/drizzle.ts (+1 -1)
📝 packages/cli/test/__snapshots__/auth-schema-number-id.txt (+13 -14)
📝 packages/cli/test/__snapshots__/auth-schema.txt (+29 -23)

📄 Description

What does this PR do?

Fixes a bug where PostgreSQL schemas were being generated with timestamp (without timezone), causing expiration checks to break due to UTC mismatches.

Why is it needed?

BetterAuth tokens like reset-password or verification-token were expiring immediately if the server and database timezones differed. This fix ensures that expiration date fields in Drizzle schemas for PostgreSQL use timestamp with time zone, making comparisons consistent regardless of environment.

Changes

  • Updated Drizzle schema generator to use timestamp(..., { withTimezone: true }) for PostgreSQL when field type is date.
  • Updated snapshot files for Drizzle and Prisma.
  • Verified all test snapshots reflect the correct schema output.

Notes

  • Untracked temporary folder packages/cli/getConfig_test-* was ignored locally and not committed.
  • No changes were needed to the test definitions—only snapshots were updated.

Closes https://github.com/better-auth/better-auth/issues/3461


Summary by cubic

Fixed a bug where PostgreSQL schemas used timestamps without time zone, causing token expiration checks to fail if server and database timezones differed.

  • Bug Fixes
    • Updated Drizzle schema generator to use timestamp(..., { withTimezone: true }) for PostgreSQL date fields.
    • Updated test snapshots to reflect the correct schema output.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/3477 **Author:** [@JuanPabloGilA](https://github.com/JuanPabloGilA) **Created:** 7/19/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/fix-timestamp-with-timezone` --- ### 📝 Commits (5) - [`57c146a`](https://github.com/better-auth/better-auth/commit/57c146a7958c7cdd60c59262658e030c001aac74) fix(drizzle): use timestamp with time zone for PostgreSQL - [`a9b0fad`](https://github.com/better-auth/better-auth/commit/a9b0fadcfa7a207636a8983ce7264b04b4d0324e) chore: apply formatting with Biome - [`e3885ec`](https://github.com/better-auth/better-auth/commit/e3885ecb03457f60461b6cf0a201697f7488effe) Merge branch 'main' into feat/fix-timestamp-with-timezone - [`9e363c5`](https://github.com/better-auth/better-auth/commit/9e363c5973c6a9631265363e5206c56aab2d62ee) remove no related files to the pr - [`4629a99`](https://github.com/better-auth/better-auth/commit/4629a997a8478da453393d646297723b4eb5ef1c) change test state to idle ### 📊 Changes **3 files changed** (+43 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `packages/cli/src/generators/drizzle.ts` (+1 -1) 📝 `packages/cli/test/__snapshots__/auth-schema-number-id.txt` (+13 -14) 📝 `packages/cli/test/__snapshots__/auth-schema.txt` (+29 -23) </details> ### 📄 Description ### What does this PR do? Fixes a bug where PostgreSQL schemas were being generated with `timestamp` (without timezone), causing expiration checks to break due to UTC mismatches. ### Why is it needed? BetterAuth tokens like `reset-password` or `verification-token` were expiring immediately if the server and database timezones differed. This fix ensures that expiration date fields in Drizzle schemas for PostgreSQL use `timestamp with time zone`, making comparisons consistent regardless of environment. ### Changes - Updated Drizzle schema generator to use `timestamp(..., { withTimezone: true })` for PostgreSQL when field type is `date`. - Updated snapshot files for Drizzle and Prisma. - Verified all test snapshots reflect the correct schema output. ### Notes - Untracked temporary folder `packages/cli/getConfig_test-*` was ignored locally and not committed. - No changes were needed to the test definitions—only snapshots were updated. Closes https://github.com/better-auth/better-auth/issues/3461 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixed a bug where PostgreSQL schemas used timestamps without time zone, causing token expiration checks to fail if server and database timezones differed. - **Bug Fixes** - Updated Drizzle schema generator to use `timestamp(..., { withTimezone: true })` for PostgreSQL date fields. - Updated test snapshots to reflect the correct schema output. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:01:50 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#4845