Repository navigation
revert(adapter-pg): stop setting search_path from the schema option (unreleased #29067) - #31190
Conversation
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]>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
size-limit report 📦
|
…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]>
Decision: the Postgres adapter does not change a connection's search path. The
schemaoption applies only to the queries Prisma Client builds, such asfindMany, 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$queryRawignore the adapter'sschema. It made the adapter open every connection with the startup parameteroptions=-c search_path=app,public, so the raw query above readapp.users. This pull request reverts #29067. It was never in a stable release, only in7.11.0-devbuilds, 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
schemawould get the startup parameter on upgrading to 7.11, and for some of them it breaks a working app:extensionsschema there, so unqualified calls to extension functions start to fail.optionsset a parameter outside its short list of known ones. An app that setsschemacan no longer connect at all.pgreads thePGOPTIONSenvironment variable only when the config has nooptions. Once the adapter adds its own, the user'sPGOPTIONSis ignored.pglets?options=in the connection string overwrite the config'soptions, 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:A user can also put
-c search_path=...in their own connectionoptions, but PgBouncer in its default configuration refuses that, so the doc comment does not recommend it. The doc comment on theschemaoption is the only source line here that is not a plain revert: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
schemaadds no startupoptionsto the pool config. The existing tests for generated queries with aschemastay.Alternatives considered
search_pathtotenant_a, the pooler gives that server connection to tenant B's client, and B'sSELECT * FROM usersreadstenant_a.users. The adapter cannot tell it is behind such a pooler, so it should not change session state by default.SET LOCALaround 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 ofschema.Agent: eeyore-69
🤖 Generated with Claude Code
Summary by CodeRabbit
search_path; the adapter no longer sets it based on the configured schema.