Skip to content

fix(pg-meta): report partition FKs once and add partition_of to list_tables - #508

Merged
barryroodt merged 2 commits into
supabase:mainfrom
sarpaydemir:fix/list-tables-partition-fk-clones
Nov 4, 2026
Merged

barryroodt merged 2 commits into
supabase:mainfrom
sarpaydemir:fix/list-tables-partition-fk-clones

Conversation

@sarpaydemir

@sarpaydemir sarpaydemir commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #507

What kind of change does this PR introduce?

Bug fix, plus an optional partition_of output field.

What is the current behavior?

list_tables reports 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 predicate pg_dump uses, so each FK is reported once. FKs declared directly on a partition are still reported.

Partitions carry partition_of, their immediate parent in the same schema.name format as name, 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 INHERITS children. A partition still names its parent when the parent's schema isn't in schemas, as target_table already does.

No change to tool names, descriptions or input schemas. partition_of is optional in the output schema. Databases without partitioned tables get identical output.

How to Review

  1. Query

    • packages/mcp-server-supabase/src/pg-meta/tables.sql
    • One predicate in the relationships subquery. conparentid rather than relispartition, which would also hide FKs declared on or pointing at a partition.
    • One scalar subquery for partition_of. It filters the parent on relkind = 'p', because INHERITS children also have pg_inherits rows.
  2. Output

    • packages/mcp-server-supabase/src/pg-meta/types.ts, packages/mcp-server-supabase/src/tools/database-operation-tools.ts
    • partition_of is omitted when null, like comment.
  3. Tests

    • packages/mcp-server-supabase/src/server.database.test.ts, next to the composite-FK tests:
    • Clones on both sides of an FK are dropped, while an FK declared on a partition is kept.
    • partition_of in both modes for a root, a partition, a sub-partition, a partition in another schema, an INHERITS parent and its child.

Review questions

  • Is the immediate parent, rather than the root, what you want in partition_of?
  • Is the public contract minimal and intentional?
  • Do the main execution paths preserve existing behavior?
  • Do tests protect observable behavior rather than implementation details?

Verification

Without the fix, the FK test fails (trimmed):

× tools > partition clones of an FK are not reported as separate constraints
AssertionError: expected [ { …(5) }, { …(5) }, { …(5) } ] to deeply equal [ { …(5) } ]
+     "name": "order_items_order_id_fkey1",
+     "target_table": "public.orders_p0",
+     "name": "order_items_order_id_fkey2",
+     "target_table": "public.orders_p1",

Without partition_of, the partition_of test fails with expected undefined to be 'public.events'. It also fails if INHERITS children are marked, if partition_of points 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 .: clean
  • Management API types regenerated: no diff
  • pnpm run build and pnpm run test:packed-platform-consumer: 3/3
  • vitest --coverage --project unit --project integration: 752 passed
  • typecheck: clean
  • tables.sql on PostgreSQL 15.19 and 17.11 with the schema from list_tables reports a foreign key once per partition when a partitioned table is involved #507, plus sub-, default and cross-schema partitions, a detached partition and INHERITS children: each FK reported once, partition_of set only on partitions

The test job's 5 e2e tests need ANTHROPIC_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_of follows the suggestion in #507.

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.
@sarpaydemir
sarpaydemir requested a review from a team as a code owner November 1, 2026 12:03
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.
@sarpaydemir sarpaydemir changed the title fix(pg-meta): skip partition clone FKs in list_tables relationships fix(pg-meta): report partition FKs once and add partition_of to list_tables Nov 2, 2026

@barryroodt barryroodt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@barryroodt
barryroodt merged commit 2c7fa82 into supabase:main Nov 4, 2026
3 of 5 checks passed
@supabase-releaser supabase-releaser Bot mentioned this pull request Nov 4, 2026
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>
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.

list_tables reports a foreign key once per partition when a partitioned table is involved

2 participants