Skip to content

fix: rewrite database/schema switching — persist schema, fix reconnect, crash-safe session list (#777)#795

Merged
datlechin merged 7 commits intomainfrom
fix/schema-persistence-rewrite
Apr 19, 2026
Merged

fix: rewrite database/schema switching — persist schema, fix reconnect, crash-safe session list (#777)#795
datlechin merged 7 commits intomainfrom
fix/schema-persistence-rewrite

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

@datlechin datlechin commented Apr 19, 2026

Closes #777

Summary

Full rewrite of the database/schema switching system. Fixes 8 bugs across persistence, encapsulation, and crash safety.

Fixes

  • Schema not restored on reconnect for PostgreSQL/Redshift/BigQuery (Persist last-used schema per connection #777)
  • Database not restored on reconnect for MySQL/MariaDB/ClickHouse (missing postConnectActions)
  • Database lost after auto-reconnect (clearCachedData was niling currentDatabase)
  • selectDatabaseFromConnectionField set state before error check (Redis state corruption)
  • Database switch closed windows before driver call confirmed success (UI damaged on failure)
  • Schema-switch branch saved to wrong UserDefaults key (lastDatabase instead of lastSchema)
  • Schema switch didn't save tabs before clearing (tab state lost)
  • Open connection IDs only saved in applicationWillTerminate (Cmd+R in Xcode lost current connection)
  • Orphaned UserDefaults keys on connection deletion

Architecture

  • DatabaseManager.switchDatabase(to:for:) and switchSchema(to:for:) own driver call + session state + persistence
  • Coordinator only handles UI effects after manager confirms success
  • PostConnectAction.selectSchemaFromLastSession for PostgreSQL/Redshift/BigQuery
  • All plugins declare their postConnectActions explicitly (not relying on registry defaults)
  • Open connection IDs persisted on every session add/remove via activeSessions.didSet

Test plan

  • Build passes
  • PostgreSQL: switch schema, Cmd+R, reconnect - schema restored
  • MySQL/MariaDB: empty DB field, switch database, reconnect - database restored
  • ClickHouse: switch database, reconnect - database restored
  • MSSQL: auto-reconnect after drop - database restored
  • Switch to non-existent database - windows and tabs preserved, error shown
  • Delete connection - no orphaned UserDefaults keys
  • Cmd+R in Xcode - correct connection restored on relaunch

@datlechin datlechin changed the title fix: rewrite database/schema switching - persistence, encapsulation, error ordering (#777) fix: rewrite database/schema switching — persist schema, fix reconnect, crash-safe session list (#777) Apr 19, 2026
@datlechin datlechin merged commit 1dda27d into main Apr 19, 2026
2 checks passed
@datlechin datlechin deleted the fix/schema-persistence-rewrite branch April 19, 2026 12:58
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.

Persist last-used schema per connection

1 participant