Skip to content

fix(sidebar): refresh table tree after dropping a table#1714

Merged
datlechin merged 4 commits into
TableProApp:mainfrom
desperadoxhy:feat/db-refresh-tables
Jun 18, 2026
Merged

fix(sidebar): refresh table tree after dropping a table#1714
datlechin merged 4 commits into
TableProApp:mainfrom
desperadoxhy:feat/db-refresh-tables

Conversation

@desperadoxhy

Copy link
Copy Markdown
Contributor

Problem

Dropping a table from the sidebar (right-click Delete, then Save Changes) did not remove it from the tree on multi-database servers like MySQL and PostgreSQL. The dropped table stayed visible until you refreshed the schema by hand.

Root cause

reloadSchema only reloaded SchemaService. The tree for .bySchema and .byDatabase servers (DatabaseTreeView) reads from DatabaseTreeMetadataService, and loadTables short-circuits once a list is loaded. Nothing refreshed that store after a drop, so the stale table list stayed put.

Fix

  • Add DatabaseTreeMetadataService.refreshLoadedTables(connectionId:): cancel dedup, clear, and refetch every expanded database/schema's tables for the connection.
  • MainContentCoordinator.reloadSchema calls it right after schemaService.reload, so both data sources update.

Scope is tables only (no routines).

Tests

Two new tests in DatabaseTreeMetadataServiceTests:

  • refetch replaces a previously loaded list after it changes
  • no-op when no tables are loaded

Both pass. App and test targets compile.

Notes

connectionObjectKeys is now nonisolated. It is a pure function with no actor state, and the old MainActor isolation broke the existing tests under Xcode 27 beta strict concurrency. Stable Xcode accepts the annotation too.

Verified by hand on a MySQL connection: drop a table from the sidebar, Save Changes, and it disappears from the tree without a manual refresh.

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Before we can merge this PR, you need to sign our Contributor License Agreement.

To sign, please comment below with:

I have read the CLA Document and I hereby sign the CLA.


I have read the CLA Document and I hereby sign the CLA.


xuhengyu seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@desperadoxhy

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA.

@datlechin

Copy link
Copy Markdown
Member

Pushed a maintainer update to this branch:

The red macOS App Tests were unrelated SQL-parser suites (Derived Table Parser / SQL Context Analyzer), not this change; the re-sync should clear them. Still needs the CLA signed on your side before it can merge. Thanks for the fix!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54b9816b32

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +235 to +238
} catch {
Self.logger.warning(
"tables refresh failed db=\(key.database, privacy: .public) schema=\(key.schema ?? "nil", privacy: .public) error=\(error.localizedDescription, privacy: .public)"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Surface refresh failures instead of keeping stale tables

When the metadata refetch fails after a successful drop or truncate, this catch only logs and leaves the old .loaded table list in tablesState; because loadTables returns immediately for loaded states, the sidebar continues to present the stale table with no error until the user manually forces an object refresh. Mark this key failed or clear it before refetching so refresh failures do not silently preserve deleted objects.

Useful? React with 👍 / 👎.

@datlechin datlechin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you.

@datlechin datlechin merged commit 20efb75 into TableProApp:main Jun 18, 2026
1 of 3 checks passed
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.

2 participants