Skip to content

revert(adapter-pg): stop setting search_path from the schema option (unreleased #29067) - #31190

Merged
wmadden-electric merged 2 commits into
v7from
bot/v7-revert-search-path
Nov 24, 2026
Merged

wmadden-electric merged 2 commits into
v7from
bot/v7-revert-search-path

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor
const adapter = new PrismaPg({ connectionString }, { schema: 'app' })

await prisma.user.findMany()                 // reads app.users, before and after this change
await prisma.$queryRaw`SELECT * FROM users`  // after this change: public.users, as in 7.10.1

Decision: the Postgres adapter does not change a connection's search path. The schema option applies only to the queries Prisma Client builds, such as findMany, which name the schema themselves. Raw SQL that needs another schema names it, or the user sets the search path on the role or the connection.

That is how every stable release behaves. #29067 changed it on the Prisma 7 branch (v7) to fix #26930, where TypedSQL and $queryRaw ignore the adapter's schema. It made the adapter open every connection with the startup parameter options=-c search_path=app,public, so the raw query above read app.users. This pull request reverts #29067. It was never in a stable release, only in 7.11.0-dev builds, so only users of those builds see a change. The cost is that #26930 is a real gap again. #29067 closed it; I will reopen it with the workaround below when this merges. (#29067 also named #24660, the same report from 2024, which was already closed as not planned and stays so.)

Why revert

Everyone who already sets schema would get the startup parameter on upgrading to 7.11, and for some of them it breaks a working app:

  1. It replaces the search path instead of adding to it. A path set on the database role or the database is lost. Supabase puts an extensions schema there, so unqualified calls to extension functions start to fail.
  2. PgBouncer in its default configuration refuses a connection whose startup options set a parameter outside its short list of known ones. An app that sets schema can no longer connect at all.
  3. pg reads the PGOPTIONS environment variable only when the config has no options. Once the adapter adds its own, the user's PGOPTIONS is ignored.
  4. pg lets ?options= in the connection string overwrite the config's options, so for those users the search path is silently not set.

Defects 3 and 4 could be patched by merging the option strings. Defect 2 cannot be fixed while the adapter sends a startup parameter, and fixing defect 1 needs the server's current path, which is not known before connecting.

What users do instead

Qualify the table in raw SQL (app.users), or set the search path on the database role:

ALTER ROLE app_user SET search_path = app, public;

A user can also put -c search_path=... in their own connection options, but PgBouncer in its default configuration refuses that, so the doc comment does not recommend it. The doc comment on the schema option is the only source line here that is not a plain revert:

/**
 * The name of the schema to use in generated queries. Raw queries are not affected: they resolve
 * unqualified names through the connection's `search_path`. Qualify the name in raw SQL
 * (`"mySchema"."User"`), or set the search path on the database role
 * (`ALTER ROLE ... SET search_path = ...`). The adapter does not set it itself, because behind a
 * connection pooler in transaction mode a session setting is shared with the pooler's other clients.
 */
schema?: string

Tests

The unit tests and the integration scenario that #29067 added for the startup parameter are removed with it. One new unit test checks that a schema adds no startup options to the pool config. The existing tests for generated queries with a schema stay.

Alternatives considered

  • Patch the startup parameter. Rejected for the reason above: the PgBouncer refusal and the lost role path remain.
  • Set the path with a query after each connection opens, in front of the existing path (draft fix(adapter-pg): put the schema on the search path after connecting, keeping the existing path #31184, closed in favour of this). It fixes all four defects. But behind a pooler in transaction mode (PgBouncer, Neon's pooled endpoint, Supabase's pooler) a session setting stays on the server connection, which the pooler then hands to another client. With one schema per tenant: tenant A's client sets search_path to tenant_a, the pooler gives that server connection to tenant B's client, and B's SELECT * FROM users reads tenant_a.users. The adapter cannot tell it is behind such a pooler, so it should not change session state by default.
  • SET LOCAL around each raw query. It does not leak, but it puts every raw query in a transaction and adds round trips, which changes behaviour for all users of schema.
  • An explicit opt-in option for the after-connect query. Possible later; it is a new feature, not part of removing a defect from the release branch.

Agent: eeyore-69

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Behavior Changes
    • Configured schemas continue to apply to generated queries. Raw queries now use the connection’s existing search_path; the adapter no longer sets it based on the configured schema.
    • The adapter no longer logs a warning when using an externally provided connection pool.

wmadden-electric and others added 2 commits November 24, 2026 07:37
This reverts commit 93ad369 (#29067) and documents on the schema option how to set the search path.

The startup parameter replaced a search path set on the role or database, made PgBouncer in its default configuration refuse the connection, caused PGOPTIONS to be ignored, and was silently overwritten by ?options= in the connection string.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…s the workarounds that work behind poolers

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Signed-off-by: willbot <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PostgreSQL adapter no longer adds a schema-based startup search_path to pool settings. Its documentation now explains how raw queries resolve unqualified names. Tests were changed to verify that schema configuration leaves startup options undefined, and a custom-schema raw-query integration scenario was removed.

Changes: PostgreSQL adapter search path

Layer / File(s) Summary
Pool configuration and search path behavior
packages/adapter-pg/src/pg.ts, packages/adapter-pg/src/__tests__/pg.test.ts, packages/integration-tests/src/__tests__/integration/postgresql/__scenarios.ts
The adapter uses the configured pool settings without adding a schema-based startup search_path. The documentation describes raw-query search path behavior. Tests now assert that startup options are undefined for a configured schema, and the custom-schema raw-query integration scenario was removed.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: marcelltoth

Merge Risk: Minimal · up to a35fe · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title says the PR reverts the change that made the adapter set search_path from the schema option. The raw summary and objectives confirm this: the startup search_path logic and its helpers are re…
Linked Issues check Passed The only linked issue, #26930, is closed and marked as historical context only. No active directly linked issue target remains, so no linked-issue coding requirements apply to this pull request. The P…
Out of Scope Changes check Passed The reviewed changes all relate to the reverted search path behavior or its documentation and tests. In packages/adapter-pg/src/pg.ts, the PR removes the schema-derived startup search_path logic and…
Full details: Title check

Explanation

The title says the PR reverts the change that made the adapter set search_path from the schema option. The raw summary and objectives confirm this: the startup search_path logic and its helpers are removed, the related tests and integration scenario are dropped, and the schema option documentation is updated. The title names the main change and the revert source (#29067). It is 87 characters, which is longer than ideal but still readable.

Full details: Linked Issues check

Explanation

The only linked issue, #26930, is closed and marked as historical context only. No active directly linked issue target remains, so no linked-issue coding requirements apply to this pull request. The PR objectives also state that no active directly linked targets remain. The PR reverts #29067, which the author states reintroduces the #26930 gap. The author plans to reopen #26930 after merge. That plan is not a coding requirement for this pull request.

Full details: Out of Scope Changes check

Explanation

The reviewed changes all relate to the reverted search path behavior or its documentation and tests. In packages/adapter-pg/src/pg.ts, the PR removes the schema-derived startup search_path logic and the helper functions that built and parsed it, and it updates the schema option documentation. Pool creation uses the configured pool settings directly. In packages/adapter-pg/src/tests/pg.test.ts, the startup-option test suite is replaced by one test that checks a provided schema adds no startup options. In __scenarios.ts, the integration scenario that checked $queryRaw in a custom schema is removed. That scenario tests the same raw-query search path behavior that this revert removes, so it is connected to the revert. The existing tests for generated queries with a schema are kept. One limit applies. packages/integration-tests/src/tests/integration/postgresql/snapshots/introspection.test.ts.snap is excluded by the rule '!**/*.snap' and was not inspected. Its changes, if any, are not verified. No unrelated change was found in the reviewed files.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: prisma/orm
  • Branch: v7
  • File: .coderabbit.yml
  • Commit: 6285605
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: d6d83175-f2f0-4a16-8bcc-b4204855f83a
Commits

Reviewing files that changed from the base of the PR and between 6285605 and a35fe0e.

Files ignored due to path filters: 1

  • packages/integration-tests/src/__tests__/integration/postgresql/__snapshots__/introspection.test.ts.snap is excluded by !**/*.snap
Files selected for processing: 3

  • packages/adapter-pg/src/__tests__/pg.test.ts
  • packages/adapter-pg/src/pg.ts
  • packages/integration-tests/src/__tests__/integration/postgresql/__scenarios.ts
Files with no reviewable changes: 1

  • packages/integration-tests/src/tests/integration/postgresql/__scenarios.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
packages/client/runtime/index-browser.js 2.29 KB (0%)
packages/client/runtime/index-browser.d.ts 3.37 KB (0%)
packages/cli/build/index.js 110 B (0%)
packages/client/prisma-client-0.0.0.tgz 25.6 MB (+0.01% 🔺)
packages/cli/prisma-0.0.0.tgz 13.52 MB (0%)
packages/bundle-size/da-workers-libsql/output.tgz 1.28 MB (0%)
packages/bundle-size/da-workers-neon/output.tgz 1.35 MB (0%)
packages/bundle-size/da-workers-pg/output.tgz 1.34 MB (-0.03% 🔽)
packages/bundle-size/da-workers-planetscale/output.tgz 1.29 MB (0%)
packages/bundle-size/da-workers-d1/output.tgz 1.26 MB (0%)

@wmadden-electric
wmadden-electric merged commit e9d17e5 into v7 Nov 24, 2026
723 of 726 checks passed
@wmadden-electric
wmadden-electric deleted the bot/v7-revert-search-path branch November 24, 2026 01:30
wmadden-electric added a commit to aartoni/prisma that referenced this pull request Nov 24, 2026
…ting search_path

Keep the connection-string fallback for the schema option (string or
PoolConfig.connectionString; libpq strings yield no schema) and drop the
startup `-csearch_path` option and URL `options` rewriting, which v7
reverted in prisma#31190: it replaced a search path set on the role, PgBouncer
refuses it, and it overrode PGOPTIONS. Raw queries keep resolving names
through the connection's own search_path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants