No way to get BIGINT columns for IDs? #2228

Open
opened 2026-03-13 09:35:55 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @aybabtme on GitHub (Oct 29, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

When requesting numeric IDs, the schema generate uses 32 bits integer columns instead of 64 bits columns.

advanced: {
  database: {
    useNumberId: true,
  },
},

Current vs. Expected behavior

It should generate 64 bits integer columns by default, or at least provide the ability to use 64 bits columns.

While some columns like organization.id and user.id might ostensibly make sense as 32bits integers (if one expects a small number of users compared to the world's population), columns like session.id should absolutely be 64 bits to avoid overflow. This is an issue that many companies faced in the past as sessions can increment quickly beyond the range representable by 32 bits integers.

Why UUIDs are not a solution.

While UUIDs sidestep this problem completely, they come with their own set of massive problems. Most databases perform poorly with random IDs as primary keys, and so performance sensitive companies tend to stick to integer IDs. Random strings as ID cause index fragmentation, poor cache locality and cache thrashing, which kill database performance. Also UUIDs compress poorly and have larger column width, leading to worse join performance and disk I/O.

Why ULIDs are not a solution

ULIDs help with the caching/index downsides of UUIDs but have poor native support by database engines and also compress poorly compared to integer sequences. They may be a stop gap solution that's less bad than 32 bits integers or UUIDs but really, 64 bits integers have been used in production at scale by large tech companies for decades now, it's kind of expected as an option.

What version of Better Auth are you using?

1.3.33

System info

"system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000",
    "release": "25.0.0",
    "cpuCount": 10,
    "cpuModel": "Apple M1 Pro",
    "totalMemory": "16.00 GB",
    "freeMemory": "0.11 GB"
  },
  "node": {
    "version": "v23.3.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.0"
  },
  "frameworks": null,
  "databases": [
    {
      "name": "mysql2",
      "version": "^3.11.0"
    }
  ],
  "betterAuth": {
    "version": "^1.3.33",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

export const auth = betterAuth({
  // ... redacted

  database: createPool({
    host: process.env.MYSQL_HOST || "localhost",
    port: parseInt(process.env.MYSQL_PORT || "3306"),
    user: process.env.MYSQL_USER || "root",
    password: process.env.MYSQL_PASSWORD || "",
    database: "betterauth_schema_gen",
  }),

  advanced: {
    database: {
      useNumberId: true,
    },
  },
});

Additional context

No response

Originally created by @aybabtme on GitHub (Oct 29, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce When requesting numeric IDs, the schema generate uses 32 bits integer columns instead of 64 bits columns. ``` advanced: { database: { useNumberId: true, }, }, ``` ### Current vs. Expected behavior It should generate 64 bits integer columns by default, or at least provide the ability to use 64 bits columns. While some columns like `organization.id` and `user.id` might ostensibly make sense as 32bits integers (if one expects a small number of users compared to the world's population), columns like `session.id` should absolutely be 64 bits to avoid overflow. This is an issue that many companies faced in the past as sessions can increment quickly beyond the range representable by 32 bits integers. ## Why UUIDs are not a solution. While UUIDs sidestep this problem completely, they come with their own set of massive problems. Most databases perform poorly with random IDs as primary keys, and so performance sensitive companies tend to stick to integer IDs. Random strings as ID cause index fragmentation, poor cache locality and cache thrashing, which kill database performance. Also UUIDs compress poorly and have larger column width, leading to worse join performance and disk I/O. ## Why ULIDs are not a solution ULIDs help with the caching/index downsides of UUIDs but have poor native support by database engines and also compress poorly compared to integer sequences. They _may_ be a stop gap solution that's *less bad than 32 bits integers or UUIDs* but really, 64 bits integers have been used in production at scale by large tech companies for decades now, it's kind of expected as an option. ### What version of Better Auth are you using? 1.3.33 ### System info ```bash "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000", "release": "25.0.0", "cpuCount": 10, "cpuModel": "Apple M1 Pro", "totalMemory": "16.00 GB", "freeMemory": "0.11 GB" }, "node": { "version": "v23.3.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.0" }, "frameworks": null, "databases": [ { "name": "mysql2", "version": "^3.11.0" } ], "betterAuth": { "version": "^1.3.33", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth = betterAuth({ // ... redacted database: createPool({ host: process.env.MYSQL_HOST || "localhost", port: parseInt(process.env.MYSQL_PORT || "3306"), user: process.env.MYSQL_USER || "root", password: process.env.MYSQL_PASSWORD || "", database: "betterauth_schema_gen", }), advanced: { database: { useNumberId: true, }, }, }); ``` ### Additional context _No response_
GiteaMirror added the enhancement label 2026-03-13 09:35:55 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 29, 2025):

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

Better Auth does not currently support generating BIGINT (64-bit integer) columns for IDs when useNumberId is enabled; it defaults to 32-bit integer columns (e.g., int in MySQL) and there is no configuration option to change this. This is a known limitation, confirmed in multiple issues and by reviewing the schema generation logic in the codebase. The recommended workaround is to manually edit the generated schema after running the CLI to change int('id') to bigint('id') or the appropriate 64-bit type for your database. There is no automated or configurable solution for BIGINT IDs at this time (source, source).

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Oct 29, 2025): <!-- Greeting --> Hi @aybabtme! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> Better Auth does not currently support generating BIGINT (64-bit integer) columns for IDs when `useNumberId` is enabled; it defaults to 32-bit integer columns (e.g., `int` in MySQL) and there is no configuration option to change this. This is a known limitation, confirmed in multiple issues and by reviewing the schema generation logic in the codebase. The recommended workaround is to manually edit the generated schema after running the CLI to change `int('id')` to `bigint('id')` or the appropriate 64-bit type for your database. There is no automated or configurable solution for BIGINT IDs at this time ([source](https://github.com/better-auth/better-auth/issues/3310), [source](https://github.com/better-auth/better-auth/issues/3227)). <!-- 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/1b46a9c6-15ae-4981-b7e0-dcd96bc5f230?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/1b46a9c6-15ae-4981-b7e0-dcd96bc5f230?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/1b46a9c6-15ae-4981-b7e0-dcd96bc5f230?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/1b46a9c6-15ae-4981-b7e0-dcd96bc5f230?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/1b46a9c6-15ae-4981-b7e0-dcd96bc5f230?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/1b46a9c6-15ae-4981-b7e0-dcd96bc5f230?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/1b46a9c6-15ae-4981-b7e0-dcd96bc5f230?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&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/5657)
Author
Owner

@VishalDevx commented on GitHub (Nov 7, 2025):

@dosu can i work on it ?

@VishalDevx commented on GitHub (Nov 7, 2025): @dosu can i work on it ?
Author
Owner

@LKNSI commented on GitHub (Dec 23, 2025):

Hey! Have been following along on this. Implementing Snowflakes was something we were excited to do, but this seems to be still blocking us. We're running Postgres + Prisma - and would love, some more love here if possible; we've tried writing adapters - but they flake and kinda overlap with our existing prisma models/controllers.

(Happy Holidays! <3)

@LKNSI commented on GitHub (Dec 23, 2025): Hey! Have been following along on this. Implementing [Snowflakes](https://en.wikipedia.org/wiki/Snowflake_ID) was something we were excited to do, but this seems to be still blocking us. We're running Postgres + Prisma - and would love, some more love here if possible; we've tried writing adapters - but they flake and kinda overlap with our existing prisma models/controllers. (Happy Holidays! <3)
Author
Owner

@uncomplexity commented on GitHub (Jan 9, 2026):

bigserial pls

we already have serial 🐱

@uncomplexity commented on GitHub (Jan 9, 2026): bigserial pls we already have serial 🐱
Author
Owner

@staz6 commented on GitHub (Jan 18, 2026):

Hello, any update on this?

@staz6 commented on GitHub (Jan 18, 2026): Hello, any update on this?
Author
Owner

@rudetrue commented on GitHub (Jan 30, 2026):

I would like to see a way to customize the id column data type as well.

If you're using Snowflake ids, or have a requirement that id's be in a certain column type for replication you're kind of stuck currently.

@rudetrue commented on GitHub (Jan 30, 2026): I would like to see a way to customize the `id` column data type as well. If you're using Snowflake ids, or have a requirement that id's be in a certain column type for replication you're kind of stuck currently.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2228