[GH-ISSUE #6198] @better-auth/cli generate: drizzle faulty relation name #19072

Closed
opened 2026-04-15 17:51:30 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @ywwa on GitHub (Nov 22, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6198

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

enough to change account.modelName to accounts and issue will be there

Current vs. Expected behavior

Currently when changing account.modelName to accounts generated schema contains following userRelations

export const userRelations = relations(user, ({ many }) => ({
  sessions: many(session),
  accountss: many(accounts),
}));

Expected to have accounts instead of accountss

What version of Better Auth are you using?

1.4.0

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1 SMP PREEMPT_DYNAMIC Fri, 14 Nov 2025 06:54:20 +0000",
    "release": "6.17.8-arch1-1",
    "cpuCount": 12,
    "cpuModel": "AMD Ryzen 5 5600X 6-Core Processor",
    "totalMemory": "31.26 GB",
    "freeMemory": "19.09 GB"
  },
  "node": {
    "version": "v22.21.0",
    "env": "development"
  },
  "packageManager": {
    "name": "pnpm",
    "version": "10.19.0"
  },
  "frameworks": [
    {
      "name": "hono",
      "version": "^4.10.4"
    }
  ],
  "databases": [
    {
      "name": "pg",
      "version": "^8.16.3"
    },
    {
      "name": "drizzle",
      "version": "^0.44.7"
    }
  ],
  "betterAuth": {
    "version": "^1.4.0",
    "config": {
      "baseURL": "http://localhost:9000",
      "secret": "[REDACTED]",
      "basePath": "/auth",
      "account": {
        "modelName": "accounts"
      }
    }
  }
}

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

Package

Auth config (if applicable)

const auth = betterAuth({
  database: drizzleAdapter(postgres, { provider: "pg" }),
  baseURL: env.BETTER_AUTH_URL,
  secret: env.BETTER_AUTH_SECRET,
  basePath: "/auth",

  account: {
    modelName: "accounts",
  },
});

Additional context

No response

Originally created by @ywwa on GitHub (Nov 22, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6198 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce enough to change `account.modelName` to `accounts` and issue will be there ### Current vs. Expected behavior Currently when changing `account.modelName` to `accounts` generated schema contains following `userRelations` ```ts export const userRelations = relations(user, ({ many }) => ({ sessions: many(session), accountss: many(accounts), })); ``` Expected to have `accounts` instead of `accountss` ### What version of Better Auth are you using? 1.4.0 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1 SMP PREEMPT_DYNAMIC Fri, 14 Nov 2025 06:54:20 +0000", "release": "6.17.8-arch1-1", "cpuCount": 12, "cpuModel": "AMD Ryzen 5 5600X 6-Core Processor", "totalMemory": "31.26 GB", "freeMemory": "19.09 GB" }, "node": { "version": "v22.21.0", "env": "development" }, "packageManager": { "name": "pnpm", "version": "10.19.0" }, "frameworks": [ { "name": "hono", "version": "^4.10.4" } ], "databases": [ { "name": "pg", "version": "^8.16.3" }, { "name": "drizzle", "version": "^0.44.7" } ], "betterAuth": { "version": "^1.4.0", "config": { "baseURL": "http://localhost:9000", "secret": "[REDACTED]", "basePath": "/auth", "account": { "modelName": "accounts" } } } } ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript const auth = betterAuth({ database: drizzleAdapter(postgres, { provider: "pg" }), baseURL: env.BETTER_AUTH_URL, secret: env.BETTER_AUTH_SECRET, basePath: "/auth", account: { modelName: "accounts", }, }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-15 17:51:30 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 22, 2025):

Thanks for reporting this issue! From your description, it looks like when you change the account model name to "accounts," the schema generation tool erroneously appends an extra “s,” resulting in “accountss” in the user relations. This appears to be a naming logic bug in the CLI generator for Drizzle. As a next step, you might try reverting to the default model name as a temporary workaround while we investigate a fix. Could you let us know if you’ve encountered similar issues with other custom model names or only with “accounts”? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3566680009 --> @better-auth-agent[bot] commented on GitHub (Nov 22, 2025): Thanks for reporting this issue! From your description, it looks like when you change the account model name to "accounts," the schema generation tool erroneously appends an extra “s,” resulting in “accountss” in the user relations. This appears to be a naming logic bug in the CLI generator for Drizzle. As a next step, you might try reverting to the default model name as a temporary workaround while we investigate a fix. Could you let us know if you’ve encountered similar issues with other custom model names or only with “accounts”? Tag @better-auth-agent if you would like an answer from the Agent. <!-- 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

@dosubot[bot] commented on GitHub (Nov 22, 2025):

Hi @ywwa! I'm Dosu and I’m helping the better-auth team.

This is a known issue in Better Auth v1.4.0: when you set a custom modelName like accounts, the code that generates relation names for Drizzle just appends an s for "many" relations, so you end up with accountss instead of accounts. The pluralization logic didn't check if the name was already pluralized, which caused this bug.

A recent update fixed this—PR #6132 (merged 2025-11-21) improved the pluralization logic in both the Drizzle adapter and CLI generators, so double s is avoided and relation names like accounts are generated correctly. Upgrading to the latest Better Auth version will resolve this problem. If you need a temporary workaround on v1.4.0, you can manually edit the generated schema to fix the relation name, but the best solution is to update to a version that includes this fix.
See PR #6132 for details

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3566681345 --> @dosubot[bot] commented on GitHub (Nov 22, 2025): <!-- Greeting --> Hi @ywwa! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known issue in Better Auth v1.4.0: when you set a custom modelName like `accounts`, the code that generates relation names for Drizzle just appends an `s` for "many" relations, so you end up with `accountss` instead of `accounts`. The pluralization logic didn't check if the name was already pluralized, which caused this bug. A recent update fixed this—PR #6132 (merged 2025-11-21) improved the pluralization logic in both the Drizzle adapter and CLI generators, so double `s` is avoided and relation names like `accounts` are generated correctly. Upgrading to the latest Better Auth version will resolve this problem. If you need a temporary workaround on v1.4.0, you can manually edit the generated schema to fix the relation name, but the best solution is to update to a version that includes this fix. [See PR #6132 for details](https://github.com/better-auth/better-auth/pull/6132) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/7f23cacd-e2dd-4d14-832f-322f42bd0161?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/7f23cacd-e2dd-4d14-832f-322f42bd0161?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/7f23cacd-e2dd-4d14-832f-322f42bd0161?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/7f23cacd-e2dd-4d14-832f-322f42bd0161?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/7f23cacd-e2dd-4d14-832f-322f42bd0161?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/7f23cacd-e2dd-4d14-832f-322f42bd0161?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/7f23cacd-e2dd-4d14-832f-322f42bd0161?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20known%20issue%20in%20Better%20Auth%20v1.4.0%3A%20when%20you%20set%20a%20custom%20modelName%20like%20%60accounts%60%2C%20the%20code%20that%20generates%20relation%20names%20for%20Drizzle%20just%20appends%20an%20%60s%60%20for%20%22many%22%20relations%2C%20so%20you%20end%20up%20with%20%60accountss%60%20instead%20of%20%60accounts%60.%20The%20pluralization%20logic%20didn%27t%20check%20if%20the%20name%20was%20already%20pluralized%2C%20which%20caused%20this%20bug.%20%0A%0AA%20recent%20update%20fixed%20this%E2%80%94PR%20%236132%20%28merged%202025-11-21%29%20improved%20the%20pluralization%20logic%20in%20both%20the%20Drizzle%20adapter%20and%20CLI%20generators%2C%20so%20double%20%60s%60%20is%20avoided%20and%20relation%20names%20like%20%60accounts%60%20are%20generated%20correctly.%20Upgrading%20to%20the%20latest%20Better%20Auth%20version%20will%20resolve%20this%20problem.%20If%20you%20need%20a%20temporary%20workaround%20on%20v1.4.0%2C%20you%20can%20manually%20edit%20the%20generated%20schema%20to%20fix%20the%20relation%20name%2C%20but%20the%20best%20solution%20is%20to%20update%20to%20a%20version%20that%20includes%20this%20fix.%20%20%0A%5BSee%20PR%20%236132%20for%20details%5D%28https%3A//github.com/better-auth/better-auth/pull/6132%29)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6198)
Author
Owner

@ping-maxwell commented on GitHub (Nov 22, 2025):

This is intentional. Even if we implemented systems to check if you modified the model name to include an s we can't just remove it since some models do actually end in s without being plural form (eg jwks)

In your case I recommend removing it manually, there isn't a way for better-auth to generate this correctly unless you made every table use plural by enabling usePlural in your drizzle adapter configuration.

<!-- gh-comment-id:3566774744 --> @ping-maxwell commented on GitHub (Nov 22, 2025): This is intentional. Even if we implemented systems to check if you modified the model name to include an `s` we can't just remove it since some models do actually end in `s` without being plural form (eg `jwks`) In your case I recommend removing it manually, there isn't a way for better-auth to generate this correctly unless you made **every** table use plural by enabling `usePlural` in your drizzle adapter configuration.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19072