[PR #5449] [MERGED] feat: enhance PostgreSQL support for non-public schema by respecting search_path configuration #14262

Closed
opened 2026-04-13 09:22:59 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5449
Author: @okisdev
Created: 10/21/2025
Status: Merged
Merged: 10/22/2025
Merged by: @Bekacru

Base: canaryHead: feat(adapters)/enhance-pg-support-for-non-public-schema


📝 Commits (5)

  • 23bc612 feat(adapters): enhance pg support for non-public schema
  • 233d5fb feat(adapters): enhance pg support for non-public schema
  • eb60c75 feat(adapters): enhance pg support for non-public schema
  • 807da05 feat(adapters): enhance pg support for non-public schema
  • d325fbc feat(adapters): enhance pg support for non-public schema

📊 Changes

6 files changed (+471 additions, -10 deletions)

View changed files

📝 docs/content/docs/adapters/postgresql.mdx (+83 -8)
📝 docs/content/docs/concepts/cli.mdx (+6 -0)
📝 docs/content/docs/concepts/database.mdx (+4 -0)
packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.pg-custom-schema.test.ts (+108 -0)
packages/better-auth/src/db/get-migration-schema.test.ts (+178 -0)
📝 packages/better-auth/src/db/get-migration.ts (+92 -2)

📄 Description

This PR enhances migrations logic for non-public schema for PostgreSQL database, especially handling the issue #5430.

Current getMigrations() function in packages/better-auth/src/db/get-migration.ts was calling db.introspection.getTables() without any schema awareness. Kysely's introspection returns tables from all visible schemas or the default public schema, however, not respecting the search_path configuration.

This PR enhances by doing the followings:

  • added helper functions for schema detection
  • added schema detection and table filtering logic before introspection
  • more test cases based on user's feedback
  • documented how enhanced logic process the migrate

This PR fixes #5430.


Summary by cubic

PostgreSQL migrations now respect the connection’s search_path, so Better Auth creates and inspects tables only in the intended (non-public) schema. This prevents conflicts with tables in other schemas and fixes #5430.

  • New Features
    • Detects current schema via SHOW search_path and filters introspection to that schema.
    • Ignores tables in other schemas (e.g., public) during migration planning.
    • Verifies schema existence and logs clear debug/warning messages.
    • Adds tests for Kysely + custom schema and schema detection, ensuring tables are created in the target schema.
    • Updates PostgreSQL docs with recommended ways to set search_path, prerequisites, and troubleshooting.

🔄 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/5449 **Author:** [@okisdev](https://github.com/okisdev) **Created:** 10/21/2025 **Status:** ✅ Merged **Merged:** 10/22/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat(adapters)/enhance-pg-support-for-non-public-schema` --- ### 📝 Commits (5) - [`23bc612`](https://github.com/better-auth/better-auth/commit/23bc6125e2962a32f079ff4d83022779be1cc7ce) feat(adapters): enhance pg support for non-public schema - [`233d5fb`](https://github.com/better-auth/better-auth/commit/233d5fb0946a67fdb0489418d77fad00da48351e) feat(adapters): enhance pg support for non-public schema - [`eb60c75`](https://github.com/better-auth/better-auth/commit/eb60c75a7b889bd1070e40283b0e31f4bb599e5c) feat(adapters): enhance pg support for non-public schema - [`807da05`](https://github.com/better-auth/better-auth/commit/807da05a0bf039f67cdf2656de077f7bfcd69458) feat(adapters): enhance pg support for non-public schema - [`d325fbc`](https://github.com/better-auth/better-auth/commit/d325fbc399784065c984b061d45c42e5f2ef0477) feat(adapters): enhance pg support for non-public schema ### 📊 Changes **6 files changed** (+471 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/adapters/postgresql.mdx` (+83 -8) 📝 `docs/content/docs/concepts/cli.mdx` (+6 -0) 📝 `docs/content/docs/concepts/database.mdx` (+4 -0) ➕ `packages/better-auth/src/adapters/kysely-adapter/test/adapter.kysely.pg-custom-schema.test.ts` (+108 -0) ➕ `packages/better-auth/src/db/get-migration-schema.test.ts` (+178 -0) 📝 `packages/better-auth/src/db/get-migration.ts` (+92 -2) </details> ### 📄 Description This PR enhances migrations logic for non-public schema for PostgreSQL database, especially handling the issue #5430. Current `getMigrations()` function in `packages/better-auth/src/db/get-migration.ts` was calling `db.introspection.getTables()` without any schema awareness. Kysely's introspection returns tables from all visible schemas or the default `public` schema, however, not respecting the `search_path` configuration. This PR enhances by doing the followings: - added helper functions for schema detection - added schema detection and table filtering logic before introspection - more test cases based on user's feedback - documented how enhanced logic process the migrate This PR fixes #5430. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic PostgreSQL migrations now respect the connection’s search_path, so Better Auth creates and inspects tables only in the intended (non-public) schema. This prevents conflicts with tables in other schemas and fixes #5430. - **New Features** - Detects current schema via SHOW search_path and filters introspection to that schema. - Ignores tables in other schemas (e.g., public) during migration planning. - Verifies schema existence and logs clear debug/warning messages. - Adds tests for Kysely + custom schema and schema detection, ensuring tables are created in the target schema. - Updates PostgreSQL docs with recommended ways to set search_path, prerequisites, and troubleshooting. <!-- 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-13 09:22:59 -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#14262