[PR #4241] [MERGED] feat: add onUpdate field on db schema generation #5273

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4241
Author: @himself65
Created: 8/26/2025
Status: Merged
Merged: 8/26/2025
Merged by: @himself65

Base: canaryHead: himself65/2025/08/26/db


📝 Commits (2)

  • 9cb61a1 feat: add onUpdate field on db schema generation
  • 9b4c216 test: update snapshot

📊 Changes

11 files changed (+548 additions, -10 deletions)

View changed files

📝 packages/better-auth/src/__snapshots__/init.test.ts.snap (+4 -0)
📝 packages/better-auth/src/db/field.ts (+7 -0)
📝 packages/better-auth/src/db/get-tables.ts (+4 -0)
📝 packages/cli/src/generators/drizzle.ts (+7 -0)
packages/cli/test/__snapshots__/auth-schema-mysql-number-id.txt (+85 -0)
packages/cli/test/__snapshots__/auth-schema-mysql.txt (+84 -0)
📝 packages/cli/test/__snapshots__/auth-schema-number-id.txt (+10 -5)
packages/cli/test/__snapshots__/auth-schema-sqlite-number-id.txt (+84 -0)
packages/cli/test/__snapshots__/auth-schema-sqlite.txt (+84 -0)
📝 packages/cli/test/__snapshots__/auth-schema.txt (+10 -5)
packages/cli/test/generate-all-db.test.ts (+169 -0)

📄 Description

Fixes: DEV-247
Fixes: https://github.com/better-auth/better-auth/issues/4187

Summary by cubic

Adds onUpdate support to schema generation so timestamp fields (like updatedAt) auto-update across PostgreSQL, MySQL, and SQLite. Generated Drizzle schemas now include .$onUpdate(() => new Date()) where applicable.

  • New Features
    • Added FieldAttributeConfig.onUpdate for fields.
    • Drizzle generator emits .$onUpdate() for date fields.
    • Applied to updatedAt in user, session, account, and verification tables.
    • Added tests and snapshots for MySQL/SQLite, including number ID variants.

🔄 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/4241 **Author:** [@himself65](https://github.com/himself65) **Created:** 8/26/2025 **Status:** ✅ Merged **Merged:** 8/26/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `himself65/2025/08/26/db` --- ### 📝 Commits (2) - [`9cb61a1`](https://github.com/better-auth/better-auth/commit/9cb61a152cedd4ac047c4bac77200d88fb2d01e7) feat: add `onUpdate` field on db schema generation - [`9b4c216`](https://github.com/better-auth/better-auth/commit/9b4c2160df1bf22d86ea362444c17f945585ad59) test: update snapshot ### 📊 Changes **11 files changed** (+548 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/__snapshots__/init.test.ts.snap` (+4 -0) 📝 `packages/better-auth/src/db/field.ts` (+7 -0) 📝 `packages/better-auth/src/db/get-tables.ts` (+4 -0) 📝 `packages/cli/src/generators/drizzle.ts` (+7 -0) ➕ `packages/cli/test/__snapshots__/auth-schema-mysql-number-id.txt` (+85 -0) ➕ `packages/cli/test/__snapshots__/auth-schema-mysql.txt` (+84 -0) 📝 `packages/cli/test/__snapshots__/auth-schema-number-id.txt` (+10 -5) ➕ `packages/cli/test/__snapshots__/auth-schema-sqlite-number-id.txt` (+84 -0) ➕ `packages/cli/test/__snapshots__/auth-schema-sqlite.txt` (+84 -0) 📝 `packages/cli/test/__snapshots__/auth-schema.txt` (+10 -5) ➕ `packages/cli/test/generate-all-db.test.ts` (+169 -0) </details> ### 📄 Description Fixes: DEV-247 Fixes: https://github.com/better-auth/better-auth/issues/4187 <!-- This is an auto-generated description by cubic. --> ## Summary by cubic Adds onUpdate support to schema generation so timestamp fields (like updatedAt) auto-update across PostgreSQL, MySQL, and SQLite. Generated Drizzle schemas now include .$onUpdate(() => new Date()) where applicable. - **New Features** - Added FieldAttributeConfig.onUpdate for fields. - Drizzle generator emits .$onUpdate() for date fields. - Applied to updatedAt in user, session, account, and verification tables. - Added tests and snapshots for MySQL/SQLite, including number ID variants. <!-- 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:16:28 -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#5273