Repository navigation
fix(pg-meta): report partition FKs once and add partition_of to list_tables - #508
Merged
barryroodt merged 2 commits intoNov 4, 2026
Merged
Conversation
Postgres clones an FK onto partitions (conparentid <> 0). The relationships subquery read every contype = 'f' row, so one FK was reported once per partition. Filter conparentid = 0, as pg_dump does.
With FK clones skipped, nothing in the output links a partition to its parent. Report the immediate partitioned parent as partition_of in compact and verbose output. INHERITS children are not marked.
Closed
2 tasks done
barryroodt
approved these changes
Nov 4, 2026
barryroodt
left a comment
Contributor
There was a problem hiding this comment.
Thanks @sarpaydemir, this looks good to go!
On your question, I'd go with the immediate parent for partition_of, since that matches what Postgres shows (\d+ prints "Partition of" with the immediate parent) and an agent can walk up the chain if it needs the root.
Merged
barryroodt
pushed a commit
that referenced
this pull request
Nov 5, 2026
🤖 I have created a release *beep* *boop* --- <details><summary>mcp-server-supabase: 0.16.0</summary> ## [0.16.0](mcp-server-supabase-v0.15.0...mcp-server-supabase-v0.16.0) (2026-11-05) ### Features * bound run_notebook cost ([#511](#511)) ([e90d110](e90d110)) * **mcp-server-supabase:** run selected notebook cells ([#514](#514)) ([8d04248](8d04248)) * **notebooks:** add delete_notebook tool with elicitation confirmation ([#510](#510)) ([f36f74a](f36f74a)) * **notebooks:** enable create_notebook and run_notebook tools ([#509](#509)) ([addc4e5](addc4e5)) ### Bug Fixes * **feedback:** accept null project_id and surface the feedback length limit ([#521](#521)) ([994f56c](994f56c)) * hint agents to re-copy malformed project refs ([#522](#522)) ([0c650bf](0c650bf)) * **notebooks:** return caller errors for client-caused notebook refusals ([#512](#512)) ([5f0d393](5f0d393)) * **pg-meta:** report partition FKs once and add partition_of to list_tables ([#508](#508)) ([2c7fa82](2c7fa82)) * **pg-meta:** return complete check expressions for NOT VALID and NO INHERIT constraints ([#517](#517)) ([c54bb40](c54bb40)) * **sql:** skip destructive confirmation for planner-only EXPLAIN ([#519](#519)) ([95745e5](95745e5)) * tolerate non-URL edge function paths in api platform ([#438](#438)) ([00d07a4](00d07a4)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: supabase-releaser[bot] <223506987+supabase-releaser[bot]@users.noreply.github.com>
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.
Closes #507
What kind of change does this PR introduce?
Bug fix, plus an optional
partition_ofoutput field.What is the current behavior?
list_tablesreports the FK clones Postgres creates for partitions as separate foreign keys, so one FK is listed once per partition. Nothing in the output marks a partition's parent.What is the new behavior?
The relationships subquery filters
conparentid = 0, the predicatepg_dumpuses, so each FK is reported once. FKs declared directly on a partition are still reported.Partitions carry
partition_of, their immediate parent in the sameschema.nameformat asname, in both compact and verbose output:{ "name": "public.events_2025", "rls_enabled": false, "rows": 0, "partition_of": "public.events" }A sub-partition points to its own parent, not the root. Other tables omit the field, including
INHERITSchildren. A partition still names its parent when the parent's schema isn't inschemas, astarget_tablealready does.No change to tool names, descriptions or input schemas.
partition_ofis optional in the output schema. Databases without partitioned tables get identical output.How to Review
Query
packages/mcp-server-supabase/src/pg-meta/tables.sqlconparentidrather thanrelispartition, which would also hide FKs declared on or pointing at a partition.partition_of. It filters the parent onrelkind = 'p', becauseINHERITSchildren also havepg_inheritsrows.Output
packages/mcp-server-supabase/src/pg-meta/types.ts,packages/mcp-server-supabase/src/tools/database-operation-tools.tspartition_ofis omitted when null, likecomment.Tests
packages/mcp-server-supabase/src/server.database.test.ts, next to the composite-FK tests:partition_ofin both modes for a root, a partition, a sub-partition, a partition in another schema, anINHERITSparent and its child.Review questions
partition_of?Verification
Without the fix, the FK test fails (trimmed):
Without
partition_of, thepartition_oftest fails withexpected undefined to be 'public.events'. It also fails ifINHERITSchildren are marked, ifpartition_ofpoints to the root, or if it uses the partition's schema instead of the parent's.With the fix, the CI steps pass locally:
biome ci .: cleanpnpm run buildandpnpm run test:packed-platform-consumer: 3/3vitest --coverage --project unit --project integration: 752 passedtypecheck: cleantables.sqlon PostgreSQL 15.19 and 17.11 with the schema fromlist_tablesreports a foreign key once per partition when a partitioned table is involved #507, plus sub-, default and cross-schema partitions, a detached partition andINHERITSchildren: each FK reported once,partition_ofset only on partitionsThe
testjob's 5 e2e tests needANTHROPIC_API_KEY, which fork PRs don't receive (same as #382 and #497).I reviewed the diff and ran the checks above locally. I used AI tooling while developing it.
Additional context
Same class of fix as #382 and #497.
partition_offollows the suggestion in #507.