[GH-ISSUE #7615] Better Auth CLI overwrites existing Prisma v7 schema.prisma configuration #10855

Closed
opened 2026-04-13 07:13:09 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @Chetan0724 on GitHub (Jan 26, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7615

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create a project with Prisma v7
  2. Initialise Prisma (this creates prisma.config.ts and a Prisma v7-style schema.prisma)
  3. Run the Better Auth CLI setup command to add auth
  4. Observe that schema.prisma file is fully rewritten

Current vs. Expected behavior

Current behavior:
The Better Auth CLI overwrites the entire schema.prisma file while adding the required auth tables.
In the process, it replaces Prisma v7 generator configuration with older defaults (e.g. prisma-client-js).

Expected behavior:
The CLI should append the required Better Auth models to the existing schema.prisma
without replacing or downgrading the existing Prisma v7 generator configuration.

What version of Better Auth are you using?

1.4.17

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Home Single Language",
    "release": "10.0.26200",
    "cpuCount": 12,
    "cpuModel": "AMD Ryzen 5 5500U with Radeon Graphics         ",
    "totalMemory": "7.33 GB",
    "freeMemory": "0.88 GB"
  },
  "node": {
    "version": "v22.14.0",
    "env": "development"
  },
  "packageManager": {
    "name": "pnpm",
    "version": "9.0.0"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "16.1.0"
    },
    {
      "name": "react",
      "version": "^19.2.0"
    }
  ],
  "databases": null,
  "betterAuth": {
    "version": "^1.4.17",
    "config": {
      "emailAndPassword": {
        "enabled": true
      }
    }
  }
}

Which area(s) are affected? (Select all that apply)

Other

Auth config (if applicable)


Additional context

This happens locally during CLI setup.
prisma.config.ts is not modified (which is correct);
Only schema.prisma is overwritten.

Originally created by @Chetan0724 on GitHub (Jan 26, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7615 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create a project with Prisma v7 2. Initialise Prisma (this creates prisma.config.ts and a Prisma v7-style schema.prisma) 3. Run the Better Auth CLI setup command to add auth 4. Observe that schema.prisma file is fully rewritten ### Current vs. Expected behavior **Current behavior:** The Better Auth CLI overwrites the entire `schema.prisma` file while adding the required auth tables. In the process, it replaces Prisma v7 generator configuration with older defaults (e.g. `prisma-client-js`). **Expected behavior:** The CLI should append the required Better Auth models to the existing `schema.prisma` without replacing or downgrading the existing Prisma v7 generator configuration. ### What version of Better Auth are you using? 1.4.17 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Home Single Language", "release": "10.0.26200", "cpuCount": 12, "cpuModel": "AMD Ryzen 5 5500U with Radeon Graphics ", "totalMemory": "7.33 GB", "freeMemory": "0.88 GB" }, "node": { "version": "v22.14.0", "env": "development" }, "packageManager": { "name": "pnpm", "version": "9.0.0" }, "frameworks": [ { "name": "next", "version": "16.1.0" }, { "name": "react", "version": "^19.2.0" } ], "databases": null, "betterAuth": { "version": "^1.4.17", "config": { "emailAndPassword": { "enabled": true } } } } ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript ``` ### Additional context This happens locally during CLI setup. `prisma.config.ts` is not modified (which is correct); Only `schema.prisma` is overwritten.
GiteaMirror added the lockedbug labels 2026-04-13 07:13:09 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 26, 2026):

The issue you're experiencing with the Better Auth CLI rewriting the existing schema.prisma file is known and has been discussed in the community. Currently, the CLI does not support appending to an existing schema file without overwriting it, which can result in the loss of specific generator configurations such as the Prisma v7 settings.

To manage this better, a feature was introduced that includes a --models-only flag—this allows the CLI to generate only the model definitions without affecting the existing generator and datasource blocks. However, this is still under active development and was only partially addressed in earlier PRs.

You might want to keep an eye on the developments related to this feature, as it is expected to alleviate such conflicts in the future. For now, you may consider manually editing your schema.prisma after running the CLI or using a post-generate script to reconstruct your configurations if necessary [1], [6].

If you have more questions or need further assistance, feel free to ask! What specific features or functionalities are you hoping Better Auth will support in your project?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3798941182 --> @better-auth-agent[bot] commented on GitHub (Jan 26, 2026): The issue you're experiencing with the Better Auth CLI rewriting the existing `schema.prisma` file is known and has been discussed in the community. Currently, the CLI does not support appending to an existing schema file without overwriting it, which can result in the loss of specific generator configurations such as the Prisma v7 settings. To manage this better, a feature was introduced that includes a `--models-only` flag—this allows the CLI to generate only the model definitions without affecting the existing generator and datasource blocks. However, this is still under active development and was only partially addressed in earlier PRs. You might want to keep an eye on the developments related to this feature, as it is expected to alleviate such conflicts in the future. For now, you may consider manually editing your `schema.prisma` after running the CLI or using a post-generate script to reconstruct your configurations if necessary [[1]](https://github.com/better-auth/better-auth/issues/7139), [[6]](https://github.com/better-auth/better-auth/pull/7195). If you have more questions or need further assistance, feel free to ask! What specific features or functionalities are you hoping Better Auth will support in your project? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@amankumarhq commented on GitHub (Jan 26, 2026):

Hey @Chetan0724

I tried to reproduce this behavior but wasn't able to see the generator downgrade you described.

When running npx @better-auth/cli generate, the CLI correctly asks to overwrite the schema.

Image

However, after proceeding, my schema.prisma retained the original configuration, and only the new Auth models and fields were added.

Original
generator client {
  provider   = "prisma-client"
  output     = "./generated/client"
}

datasource db {
  provider = "postgresql"
}

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  authorId  Int
  author    User    @relation(fields: [authorId], references: [id])
}
Overwritten
generator client {
  provider = "prisma-client"
  output   = "./generated/client"
}

datasource db {
  provider = "postgresql"
}

model User {
  id            Int       @id @default(autoincrement())
  email         String    @unique
  name          String?
  posts         Post[]
  emailVerified Boolean   @default(false)
  image         String?
  createdAt     DateTime  @default(now())
  updatedAt     DateTime  @updatedAt
  sessions      Session[]
  accounts      Account[]

  @@map("user")
}

model Post {
  id        Int     @id @default(autoincrement())
  title     String
  content   String?
  published Boolean @default(false)
  authorId  Int
  author    User    @relation(fields: [authorId], references: [id])
}

model Session {
  id        String   @id
  expiresAt DateTime
  token     String
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  ipAddress String?
  userAgent String?
  userId    String
  user      User     @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([token])
  @@index([userId])
  @@map("session")
}

model Account {
  id                    String    @id
  accountId             String
  providerId            String
  userId                String
  user                  User      @relation(fields: [userId], references: [id], onDelete: Cascade)
  accessToken           String?
  refreshToken          String?
  idToken               String?
  accessTokenExpiresAt  DateTime?
  refreshTokenExpiresAt DateTime?
  scope                 String?
  password              String?
  createdAt             DateTime  @default(now())
  updatedAt             DateTime  @updatedAt

  @@index([userId])
  @@map("account")
}

model Verification {
  id         String   @id
  identifier String
  value      String
  expiresAt  DateTime
  createdAt  DateTime @default(now())
  updatedAt  DateTime @updatedAt

  @@index([identifier])
  @@map("verification")
}
<!-- gh-comment-id:3800734807 --> @amankumarhq commented on GitHub (Jan 26, 2026): Hey @Chetan0724 I tried to reproduce this behavior but wasn't able to see the generator downgrade you described. When running `npx @better-auth/cli generate`, the CLI correctly asks to overwrite the schema. <img width="978" height="216" alt="Image" src="https://github.com/user-attachments/assets/49d5c398-475b-484e-add5-f1713dfcfa98" /> However, after proceeding, my schema.prisma retained the original configuration, and only the new Auth models and fields were added. <details> <summary>Original</summary> ``` generator client { provider = "prisma-client" output = "./generated/client" } datasource db { provider = "postgresql" } model User { id Int @id @default(autoincrement()) email String @unique name String? posts Post[] } model Post { id Int @id @default(autoincrement()) title String content String? published Boolean @default(false) authorId Int author User @relation(fields: [authorId], references: [id]) } ``` </details> <details> <summary>Overwritten</summary> ``` generator client { provider = "prisma-client" output = "./generated/client" } datasource db { provider = "postgresql" } model User { id Int @id @default(autoincrement()) email String @unique name String? posts Post[] emailVerified Boolean @default(false) image String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt sessions Session[] accounts Account[] @@map("user") } model Post { id Int @id @default(autoincrement()) title String content String? published Boolean @default(false) authorId Int author User @relation(fields: [authorId], references: [id]) } model Session { id String @id expiresAt DateTime token String createdAt DateTime @default(now()) updatedAt DateTime @updatedAt ipAddress String? userAgent String? userId String user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@unique([token]) @@index([userId]) @@map("session") } model Account { id String @id accountId String providerId String userId String user User @relation(fields: [userId], references: [id], onDelete: Cascade) accessToken String? refreshToken String? idToken String? accessTokenExpiresAt DateTime? refreshTokenExpiresAt DateTime? scope String? password String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@index([userId]) @@map("account") } model Verification { id String @id identifier String value String expiresAt DateTime createdAt DateTime @default(now()) updatedAt DateTime @updatedAt @@index([identifier]) @@map("verification") } ``` </details>
Author
Owner

@bytaesu commented on GitHub (Jan 26, 2026):

I've checked the code as well, and I can't find issues at the moment 🤔
I'm closing this, if the issue persists feel free to reopen or mention me!

<!-- gh-comment-id:3801087456 --> @bytaesu commented on GitHub (Jan 26, 2026): I've checked the code as well, and I can't find issues at the moment 🤔 I'm closing this, if the issue persists feel free to reopen or mention me! - Related to #6459
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10855