[PR #5943] [MERGED] fix: use identity instead of serial for pg schema #31939

Closed
opened 2026-04-17 22:48:51 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5943
Author: @ping-maxwell
Created: 11/12/2025
Status: Merged
Merged: 11/13/2025
Merged by: @himself65

Base: canaryHead: fix/use-identity-over-serial


📝 Commits (4)

  • 1585ac5 fix: use identity instead of serial for pg schema
  • a594d2b fix: remove logs
  • 5fdf743 fix: incorrect drizzle gen code
  • 45beb7a Merge branch 'canary' into fix/use-identity-over-serial

📊 Changes

4 files changed (+71 additions, -16 deletions)

View changed files

📝 packages/better-auth/src/db/get-migration-schema.test.ts (+54 -1)
📝 packages/better-auth/src/db/get-migration.ts (+9 -2)
📝 packages/cli/src/generators/drizzle.ts (+3 -7)
📝 packages/cli/test/__snapshots__/auth-schema-number-id.txt (+5 -6)

📄 Description

closes: https://github.com/better-auth/better-auth/issues/5549
linear: https://linear.app/better-auth/issue/ENG-661/fix-use-identity-over-serial-for-pg-number-ids

Converts pg with generateId === 'serial' to use integer with IDENTITY instead of serial


Summary by cubic

Switches Postgres numeric IDs from serial to identity across migrations and CLI schema generation, aligning with modern PG behavior and fixing #5549 and ENG-661. Generated SQL now uses integer GENERATED BY DEFAULT AS IDENTITY.

  • Bug Fixes
    • Migration generator: use sqlinteger GENERATED BY DEFAULT AS IDENTITY for Postgres when number IDs are enabled; adjust column builder to avoid double identity config.
    • CLI (Drizzle): replace serial("id") with integer("id").generatedByDefaultAsIdentity().primaryKey(); remove serial import.
    • Tests: add Postgres identity test and update snapshots to ensure no SERIAL appears.

Written for commit 45beb7a137. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/5943 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 11/12/2025 **Status:** ✅ Merged **Merged:** 11/13/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/use-identity-over-serial` --- ### 📝 Commits (4) - [`1585ac5`](https://github.com/better-auth/better-auth/commit/1585ac573a954560f8fba42782ca0b9c05221788) fix: use `identity` instead of `serial` for pg schema - [`a594d2b`](https://github.com/better-auth/better-auth/commit/a594d2b354d6ab0beeb110a2417750f00dc39420) fix: remove logs - [`5fdf743`](https://github.com/better-auth/better-auth/commit/5fdf743aeb7356c3e51e403b43dcdd6838dce21c) fix: incorrect drizzle gen code - [`45beb7a`](https://github.com/better-auth/better-auth/commit/45beb7a1373ec7e74915cdcdbad775f050948e4f) Merge branch 'canary' into fix/use-identity-over-serial ### 📊 Changes **4 files changed** (+71 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/db/get-migration-schema.test.ts` (+54 -1) 📝 `packages/better-auth/src/db/get-migration.ts` (+9 -2) 📝 `packages/cli/src/generators/drizzle.ts` (+3 -7) 📝 `packages/cli/test/__snapshots__/auth-schema-number-id.txt` (+5 -6) </details> ### 📄 Description closes: https://github.com/better-auth/better-auth/issues/5549 linear: https://linear.app/better-auth/issue/ENG-661/fix-use-identity-over-serial-for-pg-number-ids Converts `pg` with `generateId === 'serial'` to use integer with `IDENTITY` instead of `serial` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Switches Postgres numeric IDs from serial to identity across migrations and CLI schema generation, aligning with modern PG behavior and fixing #5549 and ENG-661. Generated SQL now uses integer GENERATED BY DEFAULT AS IDENTITY. - **Bug Fixes** - Migration generator: use sql`integer GENERATED BY DEFAULT AS IDENTITY` for Postgres when number IDs are enabled; adjust column builder to avoid double identity config. - CLI (Drizzle): replace serial("id") with integer("id").generatedByDefaultAsIdentity().primaryKey(); remove serial import. - Tests: add Postgres identity test and update snapshots to ensure no SERIAL appears. <sup>Written for commit 45beb7a1373ec7e74915cdcdbad775f050948e4f. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 22:48:51 -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#31939