[GH-ISSUE #3227] Generated Drizzle schema doesn't cater useIdNumber correctly #9530

Closed
opened 2026-04-13 05:01:39 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @ismi-abbas on GitHub (Jun 30, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3227

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create a config with options.advance.database.useNumberId = true
  2. Run npx @better-auth/cli generate
  3. Generated schema has int as id

Current vs. Expected behavior

  1. Expected is serial is imported for postgres, and id is serial

What version of Better Auth are you using?

^1.2.10

Provide environment information

chrome

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

Other, Backend

Auth config (if applicable)

export const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
    schema: {
      ...schema,
    },
  }),
  advanced: {
    database: {
      generateId: false,
      useNumberId: true,
    },
  },....

Additional context

No response

Originally created by @ismi-abbas on GitHub (Jun 30, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3227 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create a config with `options.advance.database.useNumberId = true` 2. Run npx @better-auth/cli generate 3. Generated schema has int as id ### Current vs. Expected behavior 1. Expected is serial is imported for postgres, and id is serial ### What version of Better Auth are you using? ^1.2.10 ### Provide environment information ```bash chrome ``` ### Which area(s) are affected? (Select all that apply) Other, Backend ### Auth config (if applicable) ```typescript export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", schema: { ...schema, }, }), advanced: { database: { generateId: false, useNumberId: true, }, },.... ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 05:01:39 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 30, 2025):

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

This is a known issue in the schema generation logic: even though the code is supposed to emit serial for Postgres when useNumberId is true, another part of the generator overrides this and outputs int instead. This happens because the generic code path for useNumberId sets the id field to int("id").autoincrement.primaryKey(), regardless of the database type, which can override the Postgres-specific serial logic see code reference.

As a workaround, after running the CLI, manually change the generated schema’s id field from int("id").autoincrement.primaryKey() to serial("id").primaryKey() for Postgres. This will ensure your schema uses serial as expected.

There’s no config-based fix at the moment; manual adjustment is the most reliable solution until the generator logic is updated to consistently respect the Postgres serial type when useNumberId is enabled.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

<!-- gh-comment-id:3019196669 --> @dosubot[bot] commented on GitHub (Jun 30, 2025): <!-- Greeting --> Hi @ismi-abbas! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known issue in the schema generation logic: even though the code is supposed to emit serial for Postgres when useNumberId is true, another part of the generator overrides this and outputs int instead. This happens because the generic code path for useNumberId sets the id field to int("id").autoincrement.primaryKey(), regardless of the database type, which can override the Postgres-specific serial logic [see code reference](https://github.com/better-auth/better-auth/blob/7c4719ed77941bc1a685dc16550be10ad980f3df/packages/cli/src/generators/drizzle.ts). As a workaround, after running the CLI, manually change the generated schema’s id field from int("id").autoincrement.primaryKey() to serial("id").primaryKey() for Postgres. This will ensure your schema uses serial as expected. There’s no config-based fix at the moment; manual adjustment is the most reliable solution until the generator logic is updated to consistently respect the Postgres serial type when useNumberId is enabled. <!-- 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/3229a304-2594-436f-a93c-09628e1511c5?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/3229a304-2594-436f-a93c-09628e1511c5?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/3229a304-2594-436f-a93c-09628e1511c5?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/3229a304-2594-436f-a93c-09628e1511c5?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/3229a304-2594-436f-a93c-09628e1511c5?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/3229a304-2594-436f-a93c-09628e1511c5?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/3229a304-2594-436f-a93c-09628e1511c5?feedback_type=other)</sup>&nbsp;&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/3227)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9530