[GH-ISSUE #5549] PG/Drizzle: useNumberId add IDENTITY option #18912

Closed
opened 2026-04-15 17:37:33 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @jose-biescas on GitHub (Oct 24, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5549

Is this suited for github?

  • Yes, this is suited for github

When using the useNumberId option for PG/Drizzle, the id column is generated as:

id: serial("id").primaryKey()

These two sources explain why serial shouldn't be used for newer applications (unless supporting Postgresql 10 or older)
And that IDENTITY is the new "SQL-standard identity column feature"

Sources:
https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_serial
https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-SERIAL

I understand having to support older versions as well, but versions before Postgresql 10 are no longer supported and version 10 had its' last updated almost 3 years ago: https://www.postgresql.org/support/versioning/

Describe the solution you'd like

Newer applications should be using the IDENTITY column

Change:

if (databaseType === "pg") {
   id = `serial("id").primaryKey()`;
} 

To:

if (databaseType === "pg") {
   id = `integer("id").generatedAlwaysAsIdentity().primaryKey()`;
} 

Provide a useLegacySerial option if people would rather use serial columns.

Describe alternatives you've considered

Remove serial entirely, and to accommodate either wanting Always or ByDefault
useNumberId can optionally take an object that describes the options

useNumberId: {
   byDefault: true // default is false
}

Additional context

No response

Originally created by @jose-biescas on GitHub (Oct 24, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5549 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. When using the `useNumberId` option for PG/Drizzle, the `id` column is generated as: ```typescript id: serial("id").primaryKey() ``` These two sources explain why `serial` shouldn't be used for newer applications (unless supporting Postgresql 10 or older) And that `IDENTITY` is the new "SQL-standard identity column feature" Sources: https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_serial https://www.postgresql.org/docs/current/datatype-numeric.html#DATATYPE-SERIAL I understand having to support older versions as well, but versions before Postgresql 10 are no longer supported and version 10 had its' last updated almost 3 years ago: https://www.postgresql.org/support/versioning/ ### Describe the solution you'd like Newer applications should be using the IDENTITY column Change: ```typescript if (databaseType === "pg") { id = `serial("id").primaryKey()`; } ``` To: ```typescript if (databaseType === "pg") { id = `integer("id").generatedAlwaysAsIdentity().primaryKey()`; } ``` Provide a `useLegacySerial` option if people would rather use serial columns. ### Describe alternatives you've considered Remove serial entirely, and to accommodate either wanting Always or ByDefault `useNumberId` can optionally take an object that describes the options ```typescript useNumberId: { byDefault: true // default is false } ``` ### Additional context _No response_
GiteaMirror added the lockedenhancement labels 2026-04-15 17:37:33 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18912