[PR #5866] fix(adapter): default value in prisma schema #6286

Open
opened 2026-03-13 12:53:30 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5866
Author: @rovertrack
Created: 11/9/2025
Status: 🔄 Open

Base: canaryHead: fix/schemaerror


📝 Commits (10+)

📊 Changes

5 files changed (+269 additions, -5 deletions)

View changed files

📝 packages/cli/src/generators/prisma.ts (+21 -3)
packages/cli/test/__snapshots__/schema-defaultvalues.prisma (+90 -0)
📝 packages/cli/test/__snapshots__/schema-mysql-custom.prisma (+2 -2)
packages/cli/test/__snapshots__/schema-mysql-defaultvalues.prisma (+90 -0)
📝 packages/cli/test/generate.test.ts (+66 -0)

📄 Description

as mentioned in #5849 the default value for Prisma schema where not generating properly,
it was because it was only looking out for the types other than number.

 additionalFields: {
      role: {
        type: "string",
        required: false,
        defaultValue: "user",
        input: false,
      },
    },

before

schema.prisma

model User {
  id            String    @id @default(uuid())
  name          String
  email         String
  emailVerified Boolean   @default(false)
  role String?
  createdAt     DateTime  @default(now())
  updatedAt     DateTime  @default(now()) @updatedAt


  @@unique([email])
  @@map("user")
}

after

schema.prisma

model User {
  id            String    @id @default(uuid())
  name          String
  email         String
  emailVerified Boolean   @default(false)
  role String? @default("user")
  createdAt     DateTime  @default(now())
  updatedAt     DateTime  @default(now()) @updatedAt
  

 

  @@unique([email])
  @@map("user")
}

now it adds the default value inPrisma schema
solves #5849.


Summary by cubic

Fixes #5849: Prisma schema generator now correctly emits default values for string, number, and boolean fields. For MySQL, short strings use @default("value"); long strings use default(dbgenerated("('value')")) with @db.Text.

  • Bug Fixes
    • Apply quoted string defaults across providers; in MySQL only for short strings.
    • Support numeric and boolean defaults: default(123), default(false).
    • Preserve special cases: createdAt @default(now()), updatedAt @updatedAt.
    • Skip function defaults to avoid invalid Prisma output.

Written for commit d34e44f630. Summary will update 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/5866 **Author:** [@rovertrack](https://github.com/rovertrack) **Created:** 11/9/2025 **Status:** 🔄 Open **Base:** `canary` ← **Head:** `fix/schemaerror` --- ### 📝 Commits (10+) - [`7c54162`](https://github.com/better-auth/better-auth/commit/7c54162238249c9cd29222a6c32aa9df0ad95a11) fix:#5849 - [`f7ed3e6`](https://github.com/better-auth/better-auth/commit/f7ed3e6c51cb574e900fef89f8fa7b22ded57fcb) fix(prismaSchema):defaultValue is not applying in prisma schema (#5849 - [`23121fc`](https://github.com/better-auth/better-auth/commit/23121fc97adb7dc8f9d13e5e0be9ca315892a265) fix:better-auth#5849 default value bug fix for prisma schema - [`4e98b80`](https://github.com/better-auth/better-auth/commit/4e98b80fff2a952e47a4ab267faeda4134794839) Merge branch 'fix/schema' of https://github.com/rovertrack/better-auth into fix/schema - [`7375631`](https://github.com/better-auth/better-auth/commit/7375631b406207f230b2a5f8b7c3ad28e42e5335) fix(prisma): add default values for role and status fields in schema - [`f520674`](https://github.com/better-auth/better-auth/commit/f520674512f8541b7b01dd847637fb0d86c2de62) Merge branch 'better-auth:canary' into fix/schema - [`e5b02b2`](https://github.com/better-auth/better-auth/commit/e5b02b2a58aa3167d85b9fb40f463a828800c627) fix(prisma): restrict default value application for string fields to non-mysql providers - [`d9c411c`](https://github.com/better-auth/better-auth/commit/d9c411c596c57a4a6b9cb2c6a068565290be0d27) Merge branch 'fix/schemaerror' of https://github.com/rovertrack/better-auth into fix/schemaerror - [`1576b22`](https://github.com/better-auth/better-auth/commit/1576b22adfcb049595ba467fe0a50fd23337294e) fix(adapter): enhance schema generation to support default values thorugh prisma - [`40bb5d1`](https://github.com/better-auth/better-auth/commit/40bb5d122b652846b6660568448924912faf58ae) Merge branch 'better-auth:canary' into fix/schemaerror ### 📊 Changes **5 files changed** (+269 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/cli/src/generators/prisma.ts` (+21 -3) ➕ `packages/cli/test/__snapshots__/schema-defaultvalues.prisma` (+90 -0) 📝 `packages/cli/test/__snapshots__/schema-mysql-custom.prisma` (+2 -2) ➕ `packages/cli/test/__snapshots__/schema-mysql-defaultvalues.prisma` (+90 -0) 📝 `packages/cli/test/generate.test.ts` (+66 -0) </details> ### 📄 Description as mentioned in #5849 the default value for Prisma schema where not generating properly, it was because it was only looking out for the types other than number. ``` additionalFields: { role: { type: "string", required: false, defaultValue: "user", input: false, }, }, ``` **before** > **schema.prisma** ``` model User { id String @id @default(uuid()) name String email String emailVerified Boolean @default(false) role String? createdAt DateTime @default(now()) updatedAt DateTime @default(now()) @updatedAt @@unique([email]) @@map("user") } ``` after > **schema.prisma** ``` model User { id String @id @default(uuid()) name String email String emailVerified Boolean @default(false) role String? @default("user") createdAt DateTime @default(now()) updatedAt DateTime @default(now()) @updatedAt @@unique([email]) @@map("user") } ``` now it adds the default value inPrisma schema solves #5849. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes #5849: Prisma schema generator now correctly emits default values for string, number, and boolean fields. For MySQL, short strings use @default("value"); long strings use default(dbgenerated("('value')")) with @db.Text. - **Bug Fixes** - Apply quoted string defaults across providers; in MySQL only for short strings. - Support numeric and boolean defaults: default(123), default(false). - Preserve special cases: createdAt @default(now()), updatedAt @updatedAt. - Skip function defaults to avoid invalid Prisma output. <sup>Written for commit d34e44f630212bd37c6c12787a6326123143b2b9. Summary will update 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-03-13 12:53:30 -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#6286