[PR #6125] [CLOSED] feat: Add support for "jsonb" type in additional fields #14712

Closed
opened 2026-04-13 09:35:57 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6125
Author: @GautamBytes
Created: 11/20/2025
Status: Closed

Base: canaryHead: feat/jsonb-support


📝 Commits (1)

  • 2a73d6e feat: add jsonb support to additional fields

📊 Changes

6 files changed (+29 additions, -11 deletions)

View changed files

📝 packages/better-auth/src/db/field.ts (+9 -7)
📝 packages/better-auth/src/db/get-migration.ts (+10 -0)
📝 packages/better-auth/src/db/to-zod.ts (+1 -1)
📝 packages/cli/src/generators/drizzle.ts (+6 -1)
📝 packages/cli/src/generators/prisma.ts (+2 -2)
📝 packages/core/src/db/type.ts (+1 -0)

📄 Description

Description

This PR adds explicit support for the jsonb field type in additionalFields. While json currently maps to jsonb in Postgres, adding this explicit type improves clarity and allows for specific Postgres optimizations while maintaining backward compatibility.
image

Changes

  • Core: Added jsonb to DBFieldType.
  • Runtime: Updated field inference to treat jsonb as an object (Record<string, any>).
  • Migrations: Mapped jsonb to the JSONB SQL type for Postgres (with fallbacks to JSON or TEXT for MySQL/SQLite/MSSQL).
  • Validation: Updated to-zod.ts to generate z.any() for jsonb fields to prevent runtime validation errors.
  • CLI: Updated Drizzle and Prisma generators to correctly map and import the jsonb type.

Impact

This is a purely additive, opt-in change. Existing json fields are unaffected.


Summary by cubic

Adds explicit support for the jsonb type in additionalFields. Improves clarity and enables Postgres-specific optimizations while keeping existing json fields unchanged.

  • New Features
    • Added jsonb to DBFieldType with runtime inference as Record<string, any>.
    • Mapped jsonb to Postgres JSONB with fallbacks: MySQL JSON, SQLite TEXT, MSSQL VARCHAR.
    • Updated Zod schema generation to handle jsonb via z.json() or z.any().
    • Updated Drizzle and Prisma generators to output jsonb correctly and adjust imports.

Written for commit 2a73d6e494. Summary will update automatically on new commits.


🔄 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/6125 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 11/20/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/jsonb-support` --- ### 📝 Commits (1) - [`2a73d6e`](https://github.com/better-auth/better-auth/commit/2a73d6e494fcc66873b9951df41c83a46fefa365) feat: add jsonb support to additional fields ### 📊 Changes **6 files changed** (+29 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/field.ts` (+9 -7) 📝 `packages/better-auth/src/db/get-migration.ts` (+10 -0) 📝 `packages/better-auth/src/db/to-zod.ts` (+1 -1) 📝 `packages/cli/src/generators/drizzle.ts` (+6 -1) 📝 `packages/cli/src/generators/prisma.ts` (+2 -2) 📝 `packages/core/src/db/type.ts` (+1 -0) </details> ### 📄 Description ### Description This PR adds explicit support for the `jsonb` field type in `additionalFields`. While `json` currently maps to `jsonb` in Postgres, adding this explicit type improves clarity and allows for specific Postgres optimizations while maintaining backward compatibility. <img width="969" height="472" alt="image" src="https://github.com/user-attachments/assets/83e2538f-1e04-4bcd-93f4-abb380f62464" /> ### Changes - **Core:** Added `jsonb` to `DBFieldType`. - **Runtime:** Updated field inference to treat `jsonb` as an object (`Record<string, any>`). - **Migrations:** Mapped `jsonb` to the `JSONB` SQL type for Postgres (with fallbacks to `JSON` or `TEXT` for MySQL/SQLite/MSSQL). - **Validation:** Updated `to-zod.ts` to generate `z.any()` for `jsonb` fields to prevent runtime validation errors. - **CLI:** Updated Drizzle and Prisma generators to correctly map and import the `jsonb` type. ### Impact This is a purely additive, opt-in change. Existing `json` fields are unaffected. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds explicit support for the jsonb type in additionalFields. Improves clarity and enables Postgres-specific optimizations while keeping existing json fields unchanged. - **New Features** - Added jsonb to DBFieldType with runtime inference as Record<string, any>. - Mapped jsonb to Postgres JSONB with fallbacks: MySQL JSON, SQLite TEXT, MSSQL VARCHAR. - Updated Zod schema generation to handle jsonb via z.json() or z.any(). - Updated Drizzle and Prisma generators to output jsonb correctly and adjust imports. <sup>Written for commit 2a73d6e494fcc66873b9951df41c83a46fefa365. Summary will update automatically on new commits.</sup> <!-- 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-04-13 09:35:57 -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#14712