Skip to content

feat: fetch databases in connection dialog#6

Open
jonasnobile wants to merge 1 commit intomainfrom
feat/fetch-databases-in-connection-form
Open

feat: fetch databases in connection dialog#6
jonasnobile wants to merge 1 commit intomainfrom
feat/fetch-databases-in-connection-form

Conversation

@jonasnobile
Copy link
Copy Markdown
Member

@jonasnobile jonasnobile commented May 4, 2026

Summary

Adds a Fetch button next to the Database field in the connection dialog that connects with the entered credentials, queries the server's catalog, and replaces the input with a dropdown to pick from. Saves users from having to know or type the database name when adding a new connection. Works for PostgreSQL and MySQL.

How it works

  • Backend: new ConnectionManager.listDatabasesForConfig(config) creates an ephemeral driver (same pattern as testConnection), connects, runs a dialect-specific catalog query (pg_database / information_schema.schemata), then disconnects. SSH tunnels are set up and torn down too. When the user hasn't picked a database yet, falls back to postgres (PG) or information_schema (MySQL). Exposed as the databases.listForConfig RPC.
  • Frontend: ConnectionDialog owns the fetched-list state. The list is auto-cleared whenever the user changes a field that targets a different server — type, host, port, user, password, SSL mode, SSH tunnel, or a pasted URL. Prevents the case where a user fetches against server A, picks a database, edits the host to server B, and silently saves a config that mixes the two.

Why "ephemeral" matters

The existing databases.list RPC requires a saved + connected connectionId, which doesn't exist while the user is filling out the dialog. The new method follows the same ephemeral pattern as testConnection so no state is registered in the connection manager — verified by a test (does not leak active drivers).

Test plan

  • bun test tests/list-databases-for-config.test.ts — 7 integration tests against PG + MariaDB (docker-compose):
    • returns seeded DB, excludes template0/template1
    • returns seeded DB, excludes mysql/information_schema/performance_schema/sys
    • sorted alphabetically
    • falls back to postgres / information_schema when DB is empty
    • bad credentials reject
    • no driver leak (ephemeral cleanup verified)
  • bun test tests/connection-manager.test.ts — added SQLite-rejection test
  • Manual UI verification still required — open the dialog, click Fetch, change host, verify the dropdown reverts to text input. I was unable to drive the browser from this session.

CI status

This branch is the feature commit only. CI's format:check, lint, and tsc will fail on pre-existing-on-main issues (CLAUDE.md trailing newline, two biome warnings in indexeddb.ts/grid.ts, a literal-key access in query-executor.ts, an unused isLinux in backend-desktop/index.ts). Those are addressed by the companion PR #7 — merge it first, then rebase this one and CI will go green. The single line in tests/connection-manager.test.ts that overlaps between the two PRs is identical (both remove the same trailing blank line), so merge order doesn't matter for that file.

Known follow-ups (not in this PR)

  • PG postgres fallback can fail on hardened installs that drop the default DB; error message will be opaque rather than actionable.
  • MySQL validateConfig requires non-empty password (pre-existing — same as testConnection); local trust auth would surface here too.
  • The Fetch RPC sends the cleartext password the same way connections.test does — same surface as before, but worth noting that the dialog now has two paths that transmit creds.

🤖 Generated with Claude Code

@jonasnobile jonasnobile force-pushed the feat/fetch-databases-in-connection-form branch from 67ee0e2 to 2acd750 Compare May 4, 2026 14:23
@jonasnobile jonasnobile force-pushed the feat/fetch-databases-in-connection-form branch 2 times, most recently from 5f02c6e to 75a9d38 Compare May 4, 2026 15:41
Adds a "Fetch" button next to the Database field that connects with
the entered credentials and replaces the input with a dropdown of
databases on the server. The list is cleared whenever the user
changes a field that would target a different server (type, host,
port, user, password, SSL, SSH tunnel, URL paste) so a database
picked from one server can't be silently saved against another.

Backed by a new listDatabasesForConfig method on ConnectionManager
that uses an ephemeral driver (mirroring testConnection) and falls
back to a maintenance database when none is given.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jonasnobile jonasnobile force-pushed the feat/fetch-databases-in-connection-form branch from 75a9d38 to 440728e Compare May 4, 2026 15:45
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.

1 participant