fix(coordinator): keep open tabs when switching schemas#1677
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 40b7306069
ℹ️ 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".
| toolbarState.currentSchema = schema | ||
|
|
||
| do { | ||
| try await DatabaseManager.shared.switchSchema(to: schema, for: connectionId) |
There was a problem hiding this comment.
Qualify table tabs before switching schemas
When a table tab was opened from the current schema, many schema-switching drivers leave tableContext.schemaName nil (for example PostgreSQL fetchTables returns PluginTableInfo(name:type:), and PluginDriverAdapter.fetchTables() maps current-schema tables with no fallback schema). Those tabs therefore store unqualified browse/edit SQL such as SELECT ... FROM "users"; after this call changes the connection search path while keeping the tab, refreshing, filtering, or saving edits in that preserved tab can target users in the newly selected schema instead of the table the tab originally displayed whenever schemas share table names. Please stamp existing table tabs with the previous schema (or otherwise qualify/close them) before switching.
Useful? React with 👍 / 👎.
Problem
Fixes #1669. On a PostgreSQL connection with multiple schemas, switching the active schema via the bottom-left schema selector closed every open tab and discarded unsaved SQL, with no way to recover it.
Root cause
MainContentCoordinator.switchSchema(to:)was a near-verbatim copy ofswitchDatabase(to:). After the driver call it rantabManager.tabs = [](plusclearFilterState(),closeSiblingNativeWindows(), a pre-wipesaveNowSync, andtabSessionRegistry.removeAll()). That wipe is correct for a database switch (tables in DB A don't exist in DB B) but wrong for a schema switch, which only changes the session'ssearch_path. Open tabs stay valid: query tabs hold user SQL, table tabs hold fully schema-qualified queries.Fix
switchSchemanow only issues the driver call and updates the schema chip. The tab wipe, filter clear, sibling-window close, pre-wipe save, and registry clear are removed.switchDatabaseis unchanged.currentSchemaChangedsubscriber now syncstoolbarState.currentSchemafrom the session before refreshing, so every window of the connection keeps a consistent schema chip, sidebar, and autocomplete now that sibling windows are no longer force-closed. The sidebar picker already reads the session directly.This matches the established native model (DataGrip: a schema/search_path selector is non-destructive to editor documents; TablePlus filed the tab-closing variant as a bug).
Tests
SwitchSchemaTests: query + table tabs and their SQL survive a schema switch,selectedTabIdis kept, and the driver/chip reflect the new schema.MockDatabaseDrivernow conforms toSchemaSwitchable(additive) so the success path is reachable in tests.swiftlint lint --strictpasses clean on all changed files.Notes