Repository navigation
fix(db): repair search_path clobbered by migration 308 - #448
Merged
Merged
Conversation
308 blanket-ran `ALTER FUNCTION ... SET search_path = <own schema>` over every function it owned, discarding the declared value on 37 functions. Five of them resolve extension objects through search_path and broke outright: core.get_jobs_with_coords ST_X/ST_Y, ::geometry -> /workers/map core.get_organizations_with_coords ST_X/ST_Y, ::geometry, citext core.validate_address_in_site ST_Contains, ::geometry core.check_site_overlaps ST_Area/Intersection/Overlaps onet.search_occupations SIMILARITY (pg_trgm) ERROR: 42704 type "geometry" does not exist The other 32 fully-qualify their references and were unaffected. 341 restores a working search_path on all five. It lists both `public` and `extensions` because 309 tries to move postgis/citext/pg_trgm into `extensions` but silently no-ops where migrations do not own the extensions -- listing both means these work either way. Every search_path stays explicit and immutable, so 308's advisor #172 posture is kept; neither schema grants CREATE to anon/authenticated, so widening resolution introduces no shadowing risk for these SECURITY DEFINER functions. 341 ends with a verification block that executes all five and raises rather than committing a silent regression. That block caught a second latent break: onet.search_occupations declares RETURNS TABLE(onetsoc_code text, title text) while the columns are character(10) and varchar(150), so RETURN QUERY raised "structure of query does not match function result type" -- and the uncast columns were also breaking SIMILARITY() overload resolution. It is recreated here with the casts. That one predates 308, as do validate_address_in_site and check_site_overlaps, which 105 declared `SET search_path = core`. 308 itself now only fills in a search_path where one is MISSING, so it can no longer overwrite a declared value on a fresh reset or in a new environment. Verified: full `supabase db reset` applies the chain clean; 341 is idempotent; get_jobs_with_coords returns 11 pins, get_organizations_with_coords 9, search_occupations ranks correctly. Refs #442, #440 Co-Authored-By: Claude Opus 5 <[email protected]>
This was referenced Jul 30, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #442. Part of #440.
What broke
308_function_search_path.sqlblanket-ranALTER FUNCTION ... SET search_path = <own schema>over every function it owned, discarding the value each function was declared with. 37 functions were rewritten. Five of them resolve extension objects throughsearch_pathand broke outright:core.get_jobs_with_coordsST_X/ST_Y,::geometry/workers/mapjob layer — the reported errorcore.get_organizations_with_coordsST_X/ST_Y,::geometry,citext/workers/maporg layercore.validate_address_in_siteST_Contains,::geometrycore.check_site_overlapsST_Area/ST_Intersection/ST_Overlapsonet.search_occupationsSIMILARITY(pg_trgm)The other 32 fully-qualify their references and were unaffected — I checked each rather than assuming.
What this does
341restores a working search_path on all five. It lists bothpublicandextensions, because309tries to move postgis/citext/pg_trgm intoextensionsbut thatALTERneeds extension ownership and silently no-ops where migrations don't own them (it no-op'd locally). Listing both means these functions work whether or not309took effect.308now only fills in a search_path where one is MISSING. It can no longer overwrite a declared value, so this cannot recur on a freshdb resetor in a newly provisioned environment.341ends with a verification block that executes all five functions andRAISEs rather than committing a silent regression.Two things that block caught
onet.search_occupationshad a second, independent break. It declaresRETURNS TABLE(onetsoc_code text, title text, ...)whileonet.occupation_datastores those ascharacter(10)andvarchar(150). plpgsqlRETURN QUERYdemands an exact type match, so it raisedstructure of query does not match function result type— and the uncast columns were also breakingSIMILARITY()overload resolution. Recreated here with casts.CREATE OR REPLACE, noDROP, so GRANTs survive.validate_address_in_siteandcheck_site_overlapswere declaredSET search_path = coreback in105, so they have never worked. Not 308's fault; fixed here regardless.Security posture
308 was chasing Supabase advisor #172 (mutable search_path). That is preserved — every
search_pathhere stays explicit and immutable. Addingpublic/extensionsintroduces no object-shadowing risk for theseSECURITY DEFINERfunctions because neither schema grantsCREATEtoanonorauthenticated(verified: onlypg_database_ownerholds it), so no untrusted role can plant a shadowing object.Verification
pnpm supa db resetapplies the entire 177-migration chain clean, with 341's verification block passingpublic.get_jobs_with_coords()→ 11 pins;public.get_organizations_with_coords()→ 9 pinsonet.search_occupations('carpenter', 3)→Carpenters0.750,Helpers--Carpenters0.500,Cabinetmakers and Bench Carpenters0.281 (verified against an inserted row, since O*NET data comes from the separatesupa:seed:onetscript)core.validate_address_in_siteandcore.check_site_overlapsexecute without errorOn CI: all six workflows are already failing on
main, pre-existing. The api suite is 113 passed / 54 failed locally; none of the 54 reference any function this PR touches, and the failures are 400/401/500 auth-class with no42704— the known ES256/auth.uid()breakage. This change is two.sqlfiles that nothing imports, so no JS/TS build or test input is affected.Follow-up, deliberately not in scope
10 functions from migrations
314–325have nosearch_pathat all — they were created after308ran, so they were never covered in either form. Pre-existing advisor gap, filed separately.