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

Open
opened 2026-04-13 09:31:21 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/5866

State: open
Merged: No


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/5866 **State:** open **Merged:** No --- 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. -->
GiteaMirror added the pull-request label 2026-04-13 09:31:21 -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#14533