Skip to content

feat(databases): migrate to dedicated databases API#94

Merged
eddietejeda merged 5 commits into
mainfrom
feat/databases-api
May 22, 2026
Merged

feat(databases): migrate to dedicated databases API#94
eddietejeda merged 5 commits into
mainfrom
feat/databases-api

Conversation

@eddietejeda
Copy link
Copy Markdown
Contributor

@eddietejeda eddietejeda commented May 22, 2026

Summary

Migrates the CLI from the deprecated /connections API to the new /databases API, adds a current-database context (mirroring the sandbox context pattern), and scopes all queries via X-Database-Id.

What changed

  • databases command rewritten — list, create, get, delete, set, and tables subcommands all hit /databases instead of /connections
  • Current database contexthotdata databases set <id> saves the active database to config; auto-set on databases create
  • --database flag on all databases tables subcommands (optional; falls back to current database)
  • X-Database-Id header — automatically sent on every API request when a database is set, so hotdata query "SELECT ..." works against the current database without extra flags
  • Footercurrent database: <id> use 'hotdata databases set' to change printed on stderr at exit (same pattern as sandbox)
  • Workspace-scoped — current database is stored as HashMap<workspace_id, database_id>; switching workspaces with --workspace-id never inherits a database set in a different workspace
  • Clear on deletedatabases delete clears the saved current database when the deleted ID was the active one, so subsequent commands don't silently send a stale X-Database-Id
  • Datasets rework — removed file/upload/URL create paths; renamed --label--description, --table-name--name; --name is required; exactly one of --sql/--query-id required

Workflow

# First time
$ hotdata databases create --description "analytics"
Database created
description: analytics
id:          dbid_abc123
current database: dbid_abc123  use 'hotdata databases set' to change

# Tables and queries use the current database automatically
$ hotdata databases tables list
TABLE                     SYNCED  LAST_SYNC
default.public.events     true    2026-05-22

$ hotdata query "SELECT count(*) FROM default.public.events"
╭───────╮
│ count │
├───────┤
│ 3399866 │
╰───────╯

# Switch by description or id
$ hotdata databases set analytics
Current database set to dbid_abc123

# Delete clears the context
$ hotdata databases delete dbid_abc123
Database deleted.
$ hotdata databases tables list
error: no current database set. Use 'hotdata databases set <id>' or pass a database id.

Test results (against production server)

Command Result
databases list ✅ Lists databases
databases set <description> ✅ Resolves by description, saves current
databases tables list (no flag) ✅ Uses current database
databases tables list --database <id> ✅ Uses explicit database, footer shows current
query "SELECT ..." ✅ Sends X-Database-Id, queries the database's tables
databases create ✅ Creates and auto-sets as current
databases delete <current> ✅ Deletes and clears current database
databases tables list after delete ✅ Errors with "no current database set"
databases set to recover ✅ Works, tables list resumes

Codex review items addressed

  • Workspace-scoped current databasecurrent_database is now stored as current_databases: HashMap<workspace_id, database_id>. Using --workspace-id ws_b will never pick up a database set under ws_a. The footer and X-Database-Id header both use the workspace that was actually resolved for the command.
  • Clear on deletedatabases delete now clears the saved current database when the deleted ID was the active one, preventing subsequent commands from silently sending a stale X-Database-Id.
  • Positional arg removal — intentional; this is a new API with no existing scripts.

🤖 Generated with Claude Code

@sentry
Copy link
Copy Markdown

sentry Bot commented May 22, 2026

Codecov Report

❌ Patch coverage is 52.21239% with 162 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/databases.rs 60.07% 107 Missing ⚠️
src/config.rs 11.90% 37 Missing ⚠️
src/main.rs 33.33% 16 Missing ⚠️
src/api.rs 60.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Comment thread src/databases.rs
Comment thread src/databases.rs
Comment thread src/command.rs
claude[bot]
claude Bot previously approved these changes May 22, 2026
Comment thread src/databases.rs Outdated
Comment thread src/databases.rs Outdated
Comment thread src/databases.rs Outdated
claude[bot]
claude Bot previously approved these changes May 22, 2026
Comment thread src/databases.rs
claude[bot]
claude Bot previously approved these changes May 22, 2026
- `current_database: Option<String>` → `current_databases: HashMap<String, String>` keyed by workspace_id, so switching workspaces no longer inherits a database set in a different workspace.
- `ApiClient::new()` now passes the resolved workspace_id into `load_current_database`, so `X-Database-Id` is only sent when it belongs to the active workspace.
- `print_database_footer()` reads `ACTIVE_WORKSPACE_ID` (set by `resolve_workspace()`) so the footer shows the correct database for the workspace actually used.
- `databases::delete()` clears `current_databases[workspace_id]` when the deleted database was the current one, preventing subsequent commands from silently sending a stale `X-Database-Id`.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread src/databases.rs
claude[bot]
claude Bot previously approved these changes May 22, 2026
- `Database.attachments` gets `#[serde(default)]` so the server can omit
  the field without causing a hard parse failure
- `try_resolve_database` percent-encodes the path segment via `urlencoding`
  so descriptions containing spaces don't crash the URL parse before the
  list fallback runs
- `create` now warns (yellow) instead of silently discarding a config save
  failure, so the user knows the implicit "set as current" didn't take
- `set(id_or_description, workspace_id)` → `set(workspace_id, id_or_description)`
  to match the argument order of every other public fn in databases.rs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@eddietejeda eddietejeda merged commit 17059bd into main May 22, 2026
11 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.

1 participant