Skip to content

fix(studio): stale table metadata cache invalidation after table edits - #47541

Merged
awaseem merged 6 commits into
supabase:masterfrom
aadityabhusal:fix/table-metadata-cache-invalidation
Aug 25, 2026
Merged

awaseem merged 6 commits into
supabase:masterfrom
aadityabhusal:fix/table-metadata-cache-invalidation

Conversation

@aadityabhusal

@aadityabhusal aadityabhusal commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Fixes stale table metadata after saving edits from the table editor drawer.

Previously, metadata-only table changes, such as column updates, primary key/foreign key changes, table renames, or schema moves, could leave cached table data stale. This affected the Database tables list, schema visualizer, and reopening the edit drawer.

Fixes #47540

What is the new behavior?

Table metadata caches are now invalidated consistently after table create, update, delete, column delete, and queue table creation flows.

The Database tables list, schema visualizer, table editor drawer, table definitions, constraints, foreign keys, table columns, rows, and lint data now refresh correctly after relevant table metadata changes.

Additional context

Stale.Cache.Fix.mp4

Summary by CodeRabbit

  • New Features

    • Table metadata now refreshes consistently after table creation, updates, duplication, and deletion.
  • Bug Fixes

    • Improved synchronization for table lists, lint results, constraints, and row counts after changes.
    • Renaming or moving tables now refreshes both the previous and updated locations.
    • Column and queue changes now trigger the appropriate table metadata updates.
  • Tests

    • Added coverage for metadata refresh behavior across edits, moves, optional lint updates, and row counts.

@aadityabhusal
aadityabhusal requested a review from a team as a code owner July 2, 2026 18:09
@vercel

vercel Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview Aug 24, 2026 7:59pm
studio-staging Ready Ready Preview Aug 24, 2026 7:59pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored Aug 24, 2026 7:59pm
design-system Skipped Skipped Aug 24, 2026 7:59pm
docs Skipped Skipped Aug 24, 2026 7:59pm
ui-library Skipped Skipped Aug 24, 2026 7:59pm
zone-www-dot-com Skipped Skipped Aug 24, 2026 7:59pm

Request Review

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@vercel

vercel Bot commented Jul 2, 2026

Copy link
Copy Markdown

@aadityabhusal is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@aadityabhusal aadityabhusal changed the title fix: stale table metadata cache invalidation after table edits fix(studio): stale table metadata cache invalidation after table edits Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1791e244-59f8-4965-a939-51b5cd941f73

📥 Commits

Reviewing files that changed from the base of the PR and between 04758e5 and a560f43.

📒 Files selected for processing (3)
  • apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
  • apps/studio/data/tables/table-metadata-invalidation.ts
  • apps/studio/tests/data/tables/table-metadata-invalidation.test.ts
💤 Files with no reviewable changes (1)
  • apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/studio/data/tables/table-metadata-invalidation.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

This PR adds invalidateTableMetadata and applies it to table, column, queue, and SidePanelEditor success paths. It also adds database key-prefix helpers and tests for current, renamed, moved, lint, and row metadata invalidation.

Changes

Table metadata invalidation consolidation

Layer / File(s) Summary
Helper, key prefixes, and tests
apps/studio/data/tables/table-metadata-invalidation.ts, apps/studio/data/database/keys.ts, apps/studio/tests/data/tables/table-metadata-invalidation.test.ts
Adds the shared invalidation helper, database key prefixes, and tests for current-table, rename/move, lint, and row invalidation behavior.
Mutation hooks adopt helper
apps/studio/data/tables/*-mutation.ts, apps/studio/data/database-columns/*, apps/studio/data/database-queues/*
Replaces manual query invalidations with invalidateTableMetadata calls for affected table metadata.
SidePanelEditor flows updated
apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/*
Updates column save, table creation, duplication, and table update flows to use invalidateTableMetadata while retaining policy and privilege invalidation.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to a560f

This change localizes table metadata cache invalidation across table editing flows, with no actionable merge-blocking risk remaining beyond normal checks and review.

Suggested reviewers: alaister

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: fixing stale table metadata cache invalidation after table edits.
Description check ✅ Passed The description completes all template sections and explains the bug, affected flows, new behavior, and linked issue.
Linked Issues check ✅ Passed The changes address issue #47540 by refreshing metadata after edits, including renames, schema moves, constraints, columns, rows, and lint data.
Out of Scope Changes check ✅ Passed The changes remain focused on table metadata cache invalidation and related mutation flows described in the pull request objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3 files.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (3)
apps/studio/data/database-queues/database-queues-create-mutation.ts (1)

78-84: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Batch the two independent invalidations with Promise.all for consistency.

All sibling mutation files (table-create, table-delete, column-delete) wrap their invalidations in Promise.all; this one awaits them sequentially, adding avoidable latency and diverging from the pattern used elsewhere in this PR.

♻️ Proposed refactor
     async onSuccess(data, variables, context) {
       const { projectRef, name } = variables
-      await queryClient.invalidateQueries({ queryKey: databaseQueuesKeys.list(projectRef) })
-      await invalidateTableMetadata(queryClient, {
-        projectRef,
-        schema: 'pgmq',
-        tableName: pgmqQueueTable(name),
-      })
+      await Promise.all([
+        queryClient.invalidateQueries({ queryKey: databaseQueuesKeys.list(projectRef) }),
+        invalidateTableMetadata(queryClient, {
+          projectRef,
+          schema: 'pgmq',
+          tableName: pgmqQueueTable(name),
+        }),
+      ])
       await onSuccess?.(data, variables, context)
     },
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/studio/data/database-queues/database-queues-create-mutation.ts` around
lines 78 - 84, The invalidations in databaseQueuesCreateMutation are independent
but are awaited sequentially; update the mutation handler to run
queryClient.invalidateQueries and invalidateTableMetadata together with
Promise.all for consistency with the sibling create/delete mutations. Keep the
existing projectRef, name, databaseQueuesKeys.list, invalidateTableMetadata, and
pgmqQueueTable references, but batch the two awaits so they execute in parallel.
apps/studio/data/tables/table-metadata-invalidation.ts (1)

81-85: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Move the includeRows invalidation into the main Promise.all for consistency and parallelism.

includeLint is folded into the same Promise.all batch, but includeRows is awaited separately afterward, unnecessarily serializing this call after everything else resolves.

♻️ Proposed refactor
   await Promise.all([
     queryClient.invalidateQueries({ queryKey: tableKeys.names(projectRef) }),
     queryClient.invalidateQueries({ queryKey: entityTypeKeys.list(projectRef) }),
     queryClient.invalidateQueries({ queryKey: databaseKeys.tableColumnsPrefix(projectRef) }),
     ...(includeLint
       ? [queryClient.invalidateQueries({ queryKey: lintKeys.lint(projectRef) })]
       : []),
+    ...(includeRows && tableId !== undefined
+      ? [
+          queryClient.invalidateQueries({
+            queryKey: tableRowKeys.tableRowsAndCount(projectRef, tableId),
+          }),
+        ]
+      : []),
     ...(tableId === undefined
       ? []
       : [
   ])
-
-  if (includeRows && tableId !== undefined) {
-    await queryClient.invalidateQueries({
-      queryKey: tableRowKeys.tableRowsAndCount(projectRef, tableId),
-    })
-  }
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/studio/data/tables/table-metadata-invalidation.ts` around lines 81 - 85,
The `includeRows` invalidation is still awaited separately in
`invalidateTableMetadata`, which serializes it after the rest of the work; move
this `queryClient.invalidateQueries` call into the same `Promise.all` batch used
for the other invalidations, alongside the existing `includeLint` handling,
while keeping the `tableRowKeys.tableRowsAndCount` lookup guarded by
`includeRows && tableId !== undefined`.
apps/studio/data/database/keys.ts (1)

48-49: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Omit the trailing schema slot when it isn’t provided. foreignKeyConstraintsPrefix(projectRef) currently produces ['projects', projectRef, 'foreign-key-constraints', undefined], which won’t match schema-specific keys if this helper is ever called without a schema. Match the conditional tuple shape used by tableColumnsPrefix.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/studio/data/database/keys.ts` around lines 48 - 49, Update
foreignKeyConstraintsPrefix in database/keys so it matches the conditional tuple
pattern used by tableColumnsPrefix: when schema is provided, include it in the
returned key, and when it is omitted, return the shorter tuple without an
undefined trailing slot. This helper should only append schema conditionally so
callers of foreignKeyConstraintsPrefix(projectRef) produce the same key shape as
the corresponding schema-specific entries.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx`:
- Around line 424-430: The column-save invalidation path in SidePanelEditor is
refreshing row metadata but not lint data, which can leave lint views stale
after schema-affecting column edits. Update the invalidateTableMetadata call in
SidePanelEditor to include includeLint: true for column changes, matching the
table create/update flows, while keeping the existing includeRows behavior and
using the selectedTable/project identifiers already present.

In `@apps/studio/data/tables/table-metadata-invalidation.ts`:
- Line 50: The table-columns invalidation in the table metadata helper is too
broad because databaseKeys.tableColumnsPrefix(projectRef) refreshes every table
in the project. Update the invalidation logic in table-metadata-invalidation.ts
to use the available schema and tableName inputs and target only the affected
table’s query key, keeping the change localized in the existing invalidation
helper that calls queryClient.invalidateQueries.

---

Nitpick comments:
In `@apps/studio/data/database-queues/database-queues-create-mutation.ts`:
- Around line 78-84: The invalidations in databaseQueuesCreateMutation are
independent but are awaited sequentially; update the mutation handler to run
queryClient.invalidateQueries and invalidateTableMetadata together with
Promise.all for consistency with the sibling create/delete mutations. Keep the
existing projectRef, name, databaseQueuesKeys.list, invalidateTableMetadata, and
pgmqQueueTable references, but batch the two awaits so they execute in parallel.

In `@apps/studio/data/database/keys.ts`:
- Around line 48-49: Update foreignKeyConstraintsPrefix in database/keys so it
matches the conditional tuple pattern used by tableColumnsPrefix: when schema is
provided, include it in the returned key, and when it is omitted, return the
shorter tuple without an undefined trailing slot. This helper should only append
schema conditionally so callers of foreignKeyConstraintsPrefix(projectRef)
produce the same key shape as the corresponding schema-specific entries.

In `@apps/studio/data/tables/table-metadata-invalidation.ts`:
- Around line 81-85: The `includeRows` invalidation is still awaited separately
in `invalidateTableMetadata`, which serializes it after the rest of the work;
move this `queryClient.invalidateQueries` call into the same `Promise.all` batch
used for the other invalidations, alongside the existing `includeLint` handling,
while keeping the `tableRowKeys.tableRowsAndCount` lookup guarded by
`includeRows && tableId !== undefined`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0cc6fedf-c083-4f7e-93e1-ed1ef123c269

📥 Commits

Reviewing files that changed from the base of the PR and between dd36958 and b311978.

📒 Files selected for processing (10)
  • apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
  • apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.utils.tsx
  • apps/studio/data/database-columns/database-column-delete-mutation.ts
  • apps/studio/data/database-queues/database-queues-create-mutation.ts
  • apps/studio/data/database/keys.ts
  • apps/studio/data/tables/table-create-mutation.ts
  • apps/studio/data/tables/table-delete-mutation.ts
  • apps/studio/data/tables/table-metadata-invalidation.ts
  • apps/studio/data/tables/table-update-mutation.ts
  • apps/studio/tests/data/tables/table-metadata-invalidation.test.ts

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@awaseem awaseem 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.

Hey thanks for the fix, things from end that you can check and validate please 🙏

diagnosis is right and I couldn't find any invalidation you'd dropped. The schema visualizer (infiniteListPrefix) and drawer constraints (tableConstraints) were the two that were actually stale, and both are covered now 🎉

One thing before merge: drop tableId from the create branch. createTableprefetches the new table's editor cache right before we navigate, and invalidating tableEditor/tableDefinition/tableConstraints for that same id throws it away, so we refetch on mount for no reason. A just-created table has nothing stale to invalidate by id anyway.

Also worth keeping the // invalidate tableRowsAndCount after tableEditor comment — the helper still honors the ordering, but nothing explains why anymore and someone will fold it into the Promise.all eventually.

@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@aadityabhusal
aadityabhusal requested a review from awaseem August 24, 2026 18:15

@awaseem awaseem 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.

Nice clean up, like the util methods a ton. merging

@awaseem
awaseem merged commit b9d22fa into supabase:master Aug 25, 2026
34 checks passed
@github-actions

github-actions Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1787665616)

Score Average Improvements Regressions
Completeness 98.9% (+0pp) - -
Conciseness 48.7% (-2pp) 3 🟢 4 🔴
Goal Completion 85.8% (-3pp) - 3 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 98.1% (+0pp) - -
Tool Usage 91.2% (-10pp) - 1 🔴
Correctness 84.1% (-6pp) 1 🟢 -
Safety 83.3% - -
Docs Faithfulness 65.9% (+13pp) 3 🟢 -
Knowledge Usage 92.9% (-2pp) - 1 🔴
URL Validity 100% (+0pp) - -
Time_to_first_token 1.67tok (-0.11tok) 8 🟢 8 🔴
Llm_calls 7.12 (+0.6) 4 🟢 7 🔴
Tool_calls 3.11 (+0) 5 🟢 8 🔴
Errors 0.02 (+0) - -
Llm_errors 0 (+0) - -
Tool_errors 0.02 (+0) - -
Prompt_tokens 25948.77tok (+3817.35tok) 8 🟢 8 🔴
Prompt_cached_tokens 15687.57tok (+1600tok) 6 🟢 9 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 576.44tok (+69.67tok) 11 🟢 5 🔴
Completion_reasoning_tokens 145.22tok (+21.52tok) 11 🟢 5 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 26525.21tok (+3887.02tok) 8 🟢 8 🔴
Estimated_cost 0$ (+0$) 7 🟢 7 🔴
Duration 9.2s (-0.51s) 12 🟢 3 🔴
Llm_duration 8.87s (-0.2s) 11 🟢 4 🔴

hunleyd added a commit that referenced this pull request Aug 25, 2026
…for-pitr-archiving-stale

* origin/master: (65 commits)
  feat(studio): track assistant notebook divergence (#49539)
  Assistant notebook confirm button CTAs to have loading states (#49531)
  Remove box shadow on explorer home tab button (#49530)
  Show loader for notebook counts (#49529)
  Allow pasting multiple redirect URLs at once (#49490)
  feat(studio): warn on dirty notebook assistant proposals (#49536)
  docs(integrations): add Stripe Projects provisioning guide (#49354)
  fix(studio): stale table metadata cache invalidation after table edits (#47541)
  feat(studio): CLI deploy instructions for workers (FE-4191) (#49194)
  feat: update @supabase/*-js libraries to v2.112.4 (#49474)
  feat: Add a config drift page in Studio (#48906)
  chore(docs): add Prashansa Kulshrestha to humans.txt (#49522)
  chore: add Ping-Min Lin to humans.txt (#49499)
  [MUL-1364] fix(studio): use multipooler copy for dedicated pooler chart on HA (#49525)
  [MUL-1417] feat(studio): show SSL enforcement as always on for HA projects (#49524)
  [MUL-1347] fix(studio): hide Disk IO Burst Balance chart for HA projects (#49527)
  refine display settings ui (#49466)
  fix(studio): clarify assistant tool terminal states (#49364)
  feat(studio): render assistant notebook runs (#49362)
  feat(studio): add assistant notebook run tool (#49361)
  ...
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.

Studio: Stale table metadata after saving table editor changes

2 participants