Skip to content

fix: scope ER diagram, dump and export to the selected database on multi-database connections#346

Merged
debba merged 2 commits into
mainfrom
fix/multi-db-context-erdiagram-export
Jun 23, 2026
Merged

fix: scope ER diagram, dump and export to the selected database on multi-database connections#346
debba merged 2 commits into
mainfrom
fix/multi-db-context-erdiagram-export

Conversation

@debba

@debba debba commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

What this fixes

When a single MySQL/MariaDB connection has several databases selected, a few features kept operating on the connection's primary database (the first one) instead of the database you actually picked:

The common cause is the same: the backend resolves the target database from the request, but the frontend never sent which database was selected, so every call fell back to database.primary().

Changes

ER diagram

  • The selected database is now forwarded to get_schema_snapshot. The MySQL driver already treats the schema argument as the database name, so each database renders its own schema. This is centralized in a small resolveDiagramSchema helper (with unit tests) and leaves PostgreSQL untouched, since it always sends an explicit schema.
  • Each diagram window now gets a unique label per connection/database/schema. Previously the window label was hard-coded, so a second diagram either collided with the first or reused its view. If a window for the same target is already open we just focus it.

Dump

  • dump_database now receives the selected database and binds the pool to it, so unqualified statements (SHOW CREATE TABLE, SELECT * FROM ...) run against the right database.
  • The dump dialog reloads the target database's tables when it opens, so the table list reflects that database instead of a stale or wrong-database list. The export button waits until the reload finishes.

Export

  • export_query_to_file now receives the selected database. The frontend resolves it from the tab's schema and falls back to the active database, matching how execute_query already resolves it (so it works whether you export a table tab or a console result after switching databases).

The new backend parameters are all optional, so PostgreSQL and SQLite behavior is unchanged.

Testing

  • cargo check passes.
  • tsc --noEmit passes.
  • Full frontend test suite passes (added cases for resolveDiagramSchema).
  • Verified on a MySQL connection with multiple databases: ER diagram, dump and export now target the selected database.

Closes #345
Closes #334

On a single MySQL/MariaDB connection that exposes several databases, the ER
diagram, the database dump and the CSV/JSON export all ran against the
connection's primary database instead of the one the user had selected. The
backend resolves the target database from the request, but the frontend never
forwarded the selected database, so it kept falling back to the first one.

ER diagram:
- Forward the selected database to get_schema_snapshot (the MySQL driver treats
  the schema argument as the database name), so each database renders its own
  tables.
- Give every diagram window a unique label per connection/database/schema and
  focus an existing one instead of silently reusing the first window.

Dump:
- Pass the selected database to dump_database so the pool connects to it and
  unqualified statements (SHOW CREATE TABLE, SELECT * FROM ...) hit the right
  database.
- Reload the target database's tables when the dialog opens so the table list
  reflects that database rather than a stale or wrong one.

Export:
- Pass the selected database to export_query_to_file, resolving it from the tab
  schema and falling back to the active database (matching how execute_query
  already resolves it).
@kilo-code-bot

kilo-code-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 4 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 3
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
src-tauri/src/dump_commands.rs 87 Header comment uses params.database (a DatabaseSelection enum) via its Display impl; for Multiple it only shows the first database. Consider using params.database.primary() explicitly for clarity.
src/components/modals/DumpDatabaseModal.tsx 55–59 refreshRef.current(databaseName) is called without error handling. If refreshDatabaseData rejects, this becomes an unhandled promise rejection.
src/components/modals/DumpDatabaseModal.tsx 136–137 databaseParam could send { database: undefined } when databaseName is falsy (e.g., empty string). The condition checks truthiness but the prop type is string which could be empty.

SUGGESTION

File Line Issue
src/components/modals/DumpDatabaseModal.tsx 220–223 Loading spinner has gap-2 class but only contains a single <Loader2 /> element with no accompanying text. Consider adding descriptive text or removing the unnecessary gap.
Files Reviewed (8 files)
  • src-tauri/src/commands.rs — Window label uniqueness fix for ER diagrams. No issues.
  • src-tauri/src/dump_commands.rs — 1 issue: params.database Display usage in header comment.
  • src-tauri/src/export.rs — No issues. Clean optional parameter addition.
  • src/components/modals/DumpDatabaseModal.tsx — 3 issues: unhandled promise rejection, potential undefined databaseParam, unnecessary gap class.
  • src/pages/Editor.tsx — No issues. Clean database parameter resolution mirroring execute_query.
  • src/pages/SchemaDiagramPage.tsx — No issues. Clean use of resolveDiagramSchema.
  • src/utils/schemaDiagram.ts — No issues. Clean helper with good documentation.
  • tests/utils/schemaDiagram.test.ts — No issues. Good test coverage for new helper.

Fix Link

Fix these issues in Kilo Cloud

@kilo-code-bot

kilo-code-bot Bot commented Jun 22, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 4 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 3
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
src-tauri/src/dump_commands.rs 87 Header comment uses params.database (a DatabaseSelection enum) via its Display impl; for Multiple it only shows the first database. Consider using params.database.primary() explicitly for clarity.
src/components/modals/DumpDatabaseModal.tsx 55–59 refreshRef.current(databaseName) is called without error handling. If refreshDatabaseData rejects, this becomes an unhandled promise rejection.
src/components/modals/DumpDatabaseModal.tsx 136–137 databaseParam could send { database: undefined } when databaseName is falsy (e.g., empty string). The condition checks truthiness but the prop type is string which could be empty.

SUGGESTION

File Line Issue
src/components/modals/DumpDatabaseModal.tsx 220–223 Loading spinner has gap-2 class but only contains a single <Loader2 /> element with no accompanying text. Consider adding descriptive text or removing the unnecessary gap.
Files Reviewed (8 files)
  • src-tauri/src/commands.rs — Window label uniqueness fix for ER diagrams. No issues.
  • src-tauri/src/dump_commands.rs — 1 issue: params.database Display usage in header comment.
  • src-tauri/src/export.rs — No issues. Clean optional parameter addition.
  • src/components/modals/DumpDatabaseModal.tsx — 3 issues: unhandled promise rejection, potential undefined databaseParam, unnecessary gap class.
  • src/pages/Editor.tsx — No issues. Clean database parameter resolution mirroring execute_query.
  • src/pages/SchemaDiagramPage.tsx — No issues. Clean use of resolveDiagramSchema.
  • src/utils/schemaDiagram.ts — No issues. Clean helper with good documentation.
  • tests/utils/schemaDiagram.test.ts — No issues. Good test coverage for new helper.

Fix Link

Fix these issues in Kilo Cloud


Reviewed by kimi-k2.6-20260420 · Input: 132.9K · Output: 31K · Cached: 1.4M

@debba debba merged commit cf7c1eb into main Jun 23, 2026
1 check 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

2 participants