[GH-ISSUE #7773] "@better-auth/cli generate" adds unnecessary double pluralisation #10899

Open
opened 2026-04-13 07:17:01 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @christophgockel on GitHub (Feb 3, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7773

Originally assigned to: @bytaesu on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Define already pluralised model names for sessions, users, accounts, etc.
  2. run @better-auth/cli generate
  3. See model relations have double s for pluralisation at the end, e.g. sessionss instead of sessions.

Current vs. Expected behavior

Current Behaviour

Relations are created with unnecessary double s as their suffix:

export const usersRelations = relations(users, ({ many }) => ({
  sessionss: many(sessions),
  accountss: many(accounts),
  memberss: many(members),
  invitationss: many(invitations),
}));

Mind the double s at the end of each relation property there: sessionss instead of sessions, etc.
Other relation tables had the same issue, but I only added the userRelations one for context.

Expected Behaviour

Relations should take already pluralised tables names into account.

export const usersRelations = relations(users, ({ many }) => ({
  sessions: many(sessions),
  accounts: many(accounts),
  members: many(members),
  invitations: many(invitations),
}));

What version of Better Auth are you using?

1.4.18

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000",
    "release": "25.2.0",
    "cpuCount": 10,
    "cpuModel": "Apple M1 Pro",
    "totalMemory": "32.00 GB",
    "freeMemory": "0.11 GB"
  },
  "node": {
    "version": "v24.13.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.6.2"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "^19.1.0"
    },
    {
      "name": "express",
      "version": "^5.1.0"
    }
  ],
  "databases": [
    {
      "name": "postgres",
      "version": "^3.4.5"
    },
    {
      "name": "drizzle",
      "version": "^0.44.7"
    }
  ],
  "betterAuth": {
    "version": "^1.4.18",
    "config": null
  }
}

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

Other

Auth config (if applicable)

import { betterAuth } from "better-auth"
import { organization } from "better-auth/plugins";

export const auth = betterAuth({
  session: {
    modelName: "sessions",
  },
  user: {
    modelName: "users",
  },
  account: {
    modelName: "accounts",
  },
  verification: {
    modelName: "verifications",
  },
  plugins: [
    organization({
      schema: {
        organization: {
          modelName: "organisations",
        },
        member: {
          modelName: "members",
        },
        invitation: {
          modelName: "invitations",
        },
      },
    }),
  ],
});

Additional context

Hi!

I've just upgraded our project to use better-auth 1.4.18 last night (from 1.3.32) and have noticed an issue in the pluralisation code when generating the (new/updated) Drizzle schema. I am not certain that this is purely Drizzle related, however.

As you can see above, we've overridden the model names to already be pluralised as it matches our existing naming pattern better.

The added relations tables that appear to be new in 1.4.x all had spelling errors in their names.

I've search open issues and MRs for this but couldn't find anything.

So I've wanted to check with the project if this is something new that I might be able to take a stab at in an MR myself, unless you're already aware of this and are potentially working on it.

Thanks!

Originally created by @christophgockel on GitHub (Feb 3, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7773 Originally assigned to: @bytaesu on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Define already pluralised model names for `sessions`, `users`, `accounts`, etc. 2. run `@better-auth/cli generate` 3. See model relations have double **s** for pluralisation at the end, e.g. `sessionss` instead of `sessions`. ### Current vs. Expected behavior #### Current Behaviour Relations are created with unnecessary double `s` as their suffix: ```ts export const usersRelations = relations(users, ({ many }) => ({ sessionss: many(sessions), accountss: many(accounts), memberss: many(members), invitationss: many(invitations), })); ``` Mind the double **s** at the end of each relation property there: `sessionss` instead of `sessions`, etc. Other relation tables had the same issue, but I only added the `userRelations` one for context. #### Expected Behaviour Relations should take already pluralised tables names into account. ```ts export const usersRelations = relations(users, ({ many }) => ({ sessions: many(sessions), accounts: many(accounts), members: many(members), invitations: many(invitations), })); ``` ### What version of Better Auth are you using? 1.4.18 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:40 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T6000", "release": "25.2.0", "cpuCount": 10, "cpuModel": "Apple M1 Pro", "totalMemory": "32.00 GB", "freeMemory": "0.11 GB" }, "node": { "version": "v24.13.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.6.2" }, "frameworks": [ { "name": "react", "version": "^19.1.0" }, { "name": "express", "version": "^5.1.0" } ], "databases": [ { "name": "postgres", "version": "^3.4.5" }, { "name": "drizzle", "version": "^0.44.7" } ], "betterAuth": { "version": "^1.4.18", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" import { organization } from "better-auth/plugins"; export const auth = betterAuth({ session: { modelName: "sessions", }, user: { modelName: "users", }, account: { modelName: "accounts", }, verification: { modelName: "verifications", }, plugins: [ organization({ schema: { organization: { modelName: "organisations", }, member: { modelName: "members", }, invitation: { modelName: "invitations", }, }, }), ], }); ``` ### Additional context Hi! I've just upgraded our project to use better-auth `1.4.18` last night (from `1.3.32`) and have noticed an issue in the pluralisation code when generating the (new/updated) Drizzle schema. I am not certain that this is purely Drizzle related, however. As you can see above, we've overridden the model names to already be pluralised as it matches our existing naming pattern better. The added relations tables that appear to be new in 1.4.x all had spelling errors in their names. I've search open issues and MRs for this but couldn't find anything. So I've wanted to check with the project if this is something new that I might be able to take a stab at in an MR myself, unless you're already aware of this and are potentially working on it. Thanks!
GiteaMirror added the breakingdevtoolsbug labels 2026-04-13 07:17:02 -05:00
Author
Owner

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

Thank you for bringing this issue to our attention! It appears that the double pluralization problem you're experiencing with @better-auth/cli generate has been reported before. Users have noted that when defining already pluralized model names, the generated relations incorrectly append an extra 's', resulting in names like sessionss instead of sessions [1], [2].

To address this, you might consider checking if there are recent updates or patches related to this issue in the repository. If you're comfortable with it, you may also want to explore creating a merge request (MR) to resolve this, especially if you have ideas for a solution!

If you need further guidance or have specific questions about implementing a fix, feel free to tag @bekacru or @ping__, who can provide more detailed assistance. What specific changes do you think you'd want to explore in your implementation?

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

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3840549960 --> @better-auth-agent[bot] commented on GitHub (Feb 3, 2026): Thank you for bringing this issue to our attention! It appears that the double pluralization problem you're experiencing with `@better-auth/cli generate` has been reported before. Users have noted that when defining already pluralized model names, the generated relations incorrectly append an extra 's', resulting in names like `sessionss` instead of `sessions` [[1]](https://github.com/better-auth/better-auth/pull/5660), [[2]](https://github.com/better-auth/better-auth/pull/6507). To address this, you might consider checking if there are recent updates or patches related to this issue in the repository. If you're comfortable with it, you may also want to explore creating a merge request (MR) to resolve this, especially if you have ideas for a solution! If you need further guidance or have specific questions about implementing a fix, feel free to tag @bekacru or @ping__, who can provide more detailed assistance. What specific changes do you think you'd want to explore in your implementation? _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

@dosubot[bot] commented on GitHub (Feb 3, 2026):

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

This is a known issue in Better Auth 1.4.x: when you set custom model names that are already plural (like sessions), the CLI generator appends another s for "many" relations, resulting in names like sessionss. This was fixed in PR #6132, which improved the pluralisation logic in both the Drizzle adapter and CLI generators to avoid double s when the model name is already pluralised. Upgrading to a version that includes this PR will resolve the problem (discussion).

If you can't upgrade yet, you can either manually edit the generated schema to fix the relation names, or (if all your tables use plural names) enable usePlural: true in your Drizzle adapter config to prevent the extra s from being added (source). Perfect automation isn't possible since some model names legitimately end with s (like jwks), so manual review may sometimes be necessary.

No need to open a new MR for this specific bug—maintainers are aware, and the fix is already merged. If you want to improve pluralisation heuristics further, contributions are always welcome!

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:3840570384 --> @dosubot[bot] commented on GitHub (Feb 3, 2026): <!-- Greeting --> Hi @christophgockel! 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 1.4.x: when you set custom model names that are already plural (like `sessions`), the CLI generator appends another `s` for "many" relations, resulting in names like `sessionss`. This was fixed in [PR #6132](https://github.com/better-auth/better-auth/pull/6132), which improved the pluralisation logic in both the Drizzle adapter and CLI generators to avoid double `s` when the model name is already pluralised. Upgrading to a version that includes this PR will resolve the problem ([discussion](https://github.com/better-auth/better-auth/discussions/7726)). If you can't upgrade yet, you can either manually edit the generated schema to fix the relation names, or (if all your tables use plural names) enable `usePlural: true` in your Drizzle adapter config to prevent the extra `s` from being added ([source](https://github.com/better-auth/better-auth/issues/6198)). Perfect automation isn't possible since some model names legitimately end with `s` (like `jwks`), so manual review may sometimes be necessary. No need to open a new MR for this specific bug—maintainers are aware, and the fix is already merged. If you want to improve pluralisation heuristics further, contributions are always welcome! <!-- 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/2e66001e-ab15-48ce-ab3e-76bb3922553a?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/2e66001e-ab15-48ce-ab3e-76bb3922553a?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/2e66001e-ab15-48ce-ab3e-76bb3922553a?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/2e66001e-ab15-48ce-ab3e-76bb3922553a?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2e66001e-ab15-48ce-ab3e-76bb3922553a?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/2e66001e-ab15-48ce-ab3e-76bb3922553a?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2e66001e-ab15-48ce-ab3e-76bb3922553a?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%201.4.x%3A%20when%20you%20set%20custom%20model%20names%20that%20are%20already%20plural%20%28like%20%60sessions%60%29%2C%20the%20CLI%20generator%20appends%20another%20%60s%60%20for%20%22many%22%20relations%2C%20resulting%20in%20names%20like%20%60sessionss%60.%20This%20was%20fixed%20in%20%5BPR%20%236132%5D%28https%3A//github.com/better-auth/better-auth/pull/6132%29%2C%20which%20improved%20the%20pluralisation%20logic%20in%20both%20the%20Drizzle%20adapter%20and%20CLI%20generators%20to%20avoid%20double%20%60s%60%20when%20the%20model%20name%20is%20already%20pluralised.%20Upgrading%20to%20a%20version%20that%20includes%20this%20PR%20will%20resolve%20the%20problem%C2%A0%28%5Bdiscussion%5D%28https%3A//github.com/better-auth/better-auth/discussions/7726%29%29.%0A%0AIf%20you%20can%27t%20upgrade%20yet%2C%20you%20can%20either%20manually%20edit%20the%20generated%20schema%20to%20fix%20the%20relation%20names%2C%20or%20%28if%20all%20your%20tables%20use%20plural%20names%29%20enable%20%60usePlural%3A%20true%60%20in%20your%20Drizzle%20adapter%20config%20to%20prevent%20the%20extra%20%60s%60%20from%20being%20added%C2%A0%28%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/6198%29%29.%20Perfect%20automation%20isn%27t%20possible%20since%20some%20model%20names%20legitimately%20end%20with%20%60s%60%20%28like%20%60jwks%60%29%2C%20so%20manual%20review%20may%20sometimes%20be%20necessary.%0A%0ANo%20need%20to%20open%20a%20new%20MR%20for%20this%20specific%20bug%E2%80%94maintainers%20are%20aware%2C%20and%20the%20fix%20is%20already%20merged.%20If%20you%20want%20to%20improve%20pluralisation%20heuristics%20further%2C%20contributions%20are%20always%20welcome%21)&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/7773)
Author
Owner

@christophgockel commented on GitHub (Feb 3, 2026):

I was not aware of the usePlural property in the Drizzle adapter.

However, I just tried this and it actually makes the situation worse because not only are the relation properties still pluralised, now the whole relation name/variable contains the double pluralisation (which is not the case without usePlural):

export const userssRelations = relations(userss, ({ many }) => ({
  memberss: many(memberss),
  invitationss: many(invitationss),
}));

export const sessionssRelations = relations(sessionss, ({ one }) => ({
  userss: one(userss, {
    fields: [sessionss.userId],
    references: [userss.id],
  }),
}));

export const accountssRelations = relations(accountss, ({ one }) => ({
  userss: one(userss, {
    fields: [accountss.userId],
    references: [userss.id],
  }),
}));

export const organisationssRelations = relations(
  organisationss,
  ({ many }) => ({
    memberss: many(memberss),
    invitationss: many(invitationss),
  }),
);

export const memberssRelations = relations(memberss, ({ one }) => ({
  organisationss: one(organisationss, {
    fields: [memberss.organisation_id],
    references: [organisationss.id],
  }),
  userss: one(userss, {
    fields: [memberss.userId],
    references: [userss.id],
  }),
}));

export const invitationssRelations = relations(invitationss, ({ one }) => ({
  organisationss: one(organisationss, {
    fields: [invitationss.organisation_id],
    references: [organisationss.id],
  }),
  userss: one(userss, {
    fields: [invitationss.inviterId],
    references: [userss.id],
  }),
}));

See the userssRelations, sessionssRelations, etc.
Without usePlural these names are correct.

<!-- gh-comment-id:3840725783 --> @christophgockel commented on GitHub (Feb 3, 2026): I was not aware of the `usePlural` property in the Drizzle adapter. However, I just tried this and it actually makes the situation worse because not only are the relation properties still pluralised, now the whole relation name/variable contains the double pluralisation (which is not the case without usePlural): ```ts export const userssRelations = relations(userss, ({ many }) => ({ memberss: many(memberss), invitationss: many(invitationss), })); export const sessionssRelations = relations(sessionss, ({ one }) => ({ userss: one(userss, { fields: [sessionss.userId], references: [userss.id], }), })); export const accountssRelations = relations(accountss, ({ one }) => ({ userss: one(userss, { fields: [accountss.userId], references: [userss.id], }), })); export const organisationssRelations = relations( organisationss, ({ many }) => ({ memberss: many(memberss), invitationss: many(invitationss), }), ); export const memberssRelations = relations(memberss, ({ one }) => ({ organisationss: one(organisationss, { fields: [memberss.organisation_id], references: [organisationss.id], }), userss: one(userss, { fields: [memberss.userId], references: [userss.id], }), })); export const invitationssRelations = relations(invitationss, ({ one }) => ({ organisationss: one(organisationss, { fields: [invitationss.organisation_id], references: [organisationss.id], }), userss: one(userss, { fields: [invitationss.inviterId], references: [userss.id], }), })); ``` See the `userssRelations`, `sessionssRelations`, etc. Without `usePlural` these names are correct.
Author
Owner

@bytaesu commented on GitHub (Feb 3, 2026):

Hi @christophgockel, I'm looking into this

<!-- gh-comment-id:3841200031 --> @bytaesu commented on GitHub (Feb 3, 2026): Hi @christophgockel, I'm looking into this
Author
Owner

@christophgockel commented on GitHub (Feb 3, 2026):

Hi @christophgockel, I'm looking into this

Thank you, much appreciated!

I've noticed the suggestions in the linked discussions sometimes mention to manually remove the double "s" from some identifiers. That's not the worst outcome and what I did yesterday, too. Having an always correct pluralisation implementation is unfortunately non-trivial. I did think that something like the double "s" is something that could be addressed maybe?
But even if not, keeping an eye out on these misspellings is also acceptable in my opinion.

<!-- gh-comment-id:3841222150 --> @christophgockel commented on GitHub (Feb 3, 2026): > Hi [@christophgockel](https://github.com/christophgockel), I'm looking into this Thank you, much appreciated! I've noticed the suggestions in the linked discussions sometimes mention to manually remove the double "s" from some identifiers. That's not the worst outcome and what I did yesterday, too. Having an always correct pluralisation implementation is unfortunately non-trivial. I did think that something like the double "s" is something that could be addressed maybe? But even if not, keeping an eye out on these misspellings is also acceptable in my opinion.
Author
Owner

@bytaesu commented on GitHub (Feb 4, 2026):

@christophgockel,

After adding the pluralization logic I'm thinking that even if it's not grammatically perfect just appending "s" might be safer for DB operations and changing it would be a breaking change..

Still thinking it over 🤔

<!-- gh-comment-id:3845527132 --> @bytaesu commented on GitHub (Feb 4, 2026): @christophgockel, After adding the pluralization logic I'm thinking that even if it's not grammatically perfect just appending `"s"` might be safer for DB operations and changing it would be a breaking change.. Still thinking it over 🤔
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10899