[PR #6145] [MERGED] fix: support kysely + pg with schema references in modelName #32081

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6145
Author: @ping-maxwell
Created: 11/20/2025
Status: Merged
Merged: 11/22/2025
Merged by: @Bekacru

Base: canaryHead: fix/pg-kysely-support-schema-ref-model-names


📝 Commits (10+)

  • 740568e fix: support kysely + pg with schema references in modelName
  • 5e10bc8 chore: lint
  • f7e44c8 Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names
  • e2292f2 Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names
  • 9ad62d6 Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names
  • 9d75273 fix
  • a8d190b Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names
  • 1af20e7 Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names
  • 609471a Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names
  • 78ef39c Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names

📊 Changes

6 files changed (+119 additions, -57 deletions)

View changed files

📝 packages/better-auth/src/adapters/create-test-suite.ts (+3 -22)
📝 packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts (+41 -27)
📝 packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.pg.test.ts (+10 -1)
📝 packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.sqlite.test.ts (+1 -1)
packages/better-auth/src/adapters/kysely-adapter/test/schema-reference-test-suite.ts (+61 -0)
📝 packages/better-auth/src/adapters/test-adapter.ts (+3 -6)

📄 Description

In the past we supported (though unintentionally) the ability to write <schema>.<model> in the modelName of the auth config and kysely with postgres and it would just work.

Since the addition of changes to Kysely adapter after join pr, we've reached a regression. This PR resolves this.


Summary by cubic

Restores support for schema-qualified modelName (e.g., internal.users) in the Kysely + Postgres adapter, including joins. Fixes the regression introduced by recent join changes.

  • Bug Fixes
    • Parse and handle <schema>.<model> in join queries; alias joins as join_<model>.
    • Use a primary alias for the base table to avoid name collisions in selections and joins.
    • Correct joined column mapping using a separate joinModelRef for accurate result reconstruction.
    • Update test cleanup to resolve default model names; add PG schema-reference tests (with and without joins).

Written for commit a3d98ebced. 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/6145 **Author:** [@ping-maxwell](https://github.com/ping-maxwell) **Created:** 11/20/2025 **Status:** ✅ Merged **Merged:** 11/22/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `fix/pg-kysely-support-schema-ref-model-names` --- ### 📝 Commits (10+) - [`740568e`](https://github.com/better-auth/better-auth/commit/740568eb4ec4a41c45015bb09b3ec1fa0662dfca) fix: support kysely + pg with schema references in `modelName` - [`5e10bc8`](https://github.com/better-auth/better-auth/commit/5e10bc8e7d8b4ebf496cb494e4e24f5328d7c193) chore: lint - [`f7e44c8`](https://github.com/better-auth/better-auth/commit/f7e44c84c0172f9fd9c232dc31b5143c3592a9b6) Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names - [`e2292f2`](https://github.com/better-auth/better-auth/commit/e2292f27edd2d665cbdf7310000e367f8b7cf9d5) Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names - [`9ad62d6`](https://github.com/better-auth/better-auth/commit/9ad62d61307767a17ea79fb3f7f0a6b80e2f2862) Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names - [`9d75273`](https://github.com/better-auth/better-auth/commit/9d75273c6f92c0345558e1566addc631a2ffd7b3) fix - [`a8d190b`](https://github.com/better-auth/better-auth/commit/a8d190bb7ac605c2af431a1d45a2b4cfc97e73d2) Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names - [`1af20e7`](https://github.com/better-auth/better-auth/commit/1af20e76c78f749855eb426cad3767cb9629bdbc) Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names - [`609471a`](https://github.com/better-auth/better-auth/commit/609471a3fb11e6e84498bbb320e172f92dc9204a) Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names - [`78ef39c`](https://github.com/better-auth/better-auth/commit/78ef39c32ea2d210b8b44f932d20ade4ef353141) Merge branch 'canary' into fix/pg-kysely-support-schema-ref-model-names ### 📊 Changes **6 files changed** (+119 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/adapters/create-test-suite.ts` (+3 -22) 📝 `packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts` (+41 -27) 📝 `packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.pg.test.ts` (+10 -1) 📝 `packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.sqlite.test.ts` (+1 -1) ➕ `packages/better-auth/src/adapters/kysely-adapter/test/schema-reference-test-suite.ts` (+61 -0) 📝 `packages/better-auth/src/adapters/test-adapter.ts` (+3 -6) </details> ### 📄 Description In the past we supported (though unintentionally) the ability to write `<schema>.<model>` in the `modelName` of the auth config and kysely with `postgres` and it would just work. Since the addition of changes to Kysely adapter after join pr, we've reached a regression. This PR resolves this. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Restores support for schema-qualified modelName (e.g., internal.users) in the Kysely + Postgres adapter, including joins. Fixes the regression introduced by recent join changes. - **Bug Fixes** - Parse and handle `<schema>.<model>` in join queries; alias joins as `join_<model>`. - Use a `primary` alias for the base table to avoid name collisions in selections and joins. - Correct joined column mapping using a separate `joinModelRef` for accurate result reconstruction. - Update test cleanup to resolve default model names; add PG schema-reference tests (with and without joins). <sup>Written for commit a3d98ebcedc34b43c239aefcfde194f566eadbe3. 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:56:40 -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#32081