feat(databases): migrate to dedicated databases API#94
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
- `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>
- `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>
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates the CLI from the deprecated
/connectionsAPI to the new/databasesAPI, adds a current-database context (mirroring the sandbox context pattern), and scopes all queries viaX-Database-Id.What changed
databasescommand rewritten — list, create, get, delete, set, and tables subcommands all hit/databasesinstead of/connectionshotdata databases set <id>saves the active database to config; auto-set ondatabases create--databaseflag on alldatabases tablessubcommands (optional; falls back to current database)X-Database-Idheader — automatically sent on every API request when a database is set, sohotdata query "SELECT ..."works against the current database without extra flagscurrent database: <id> use 'hotdata databases set' to changeprinted on stderr at exit (same pattern as sandbox)HashMap<workspace_id, database_id>; switching workspaces with--workspace-idnever inherits a database set in a different workspacedatabases deleteclears the saved current database when the deleted ID was the active one, so subsequent commands don't silently send a staleX-Database-Id--label→--description,--table-name→--name;--nameis required; exactly one of--sql/--query-idrequiredWorkflow
Test results (against production server)
databases listdatabases set <description>databases tables list(no flag)databases tables list --database <id>query "SELECT ..."X-Database-Id, queries the database's tablesdatabases createdatabases delete <current>databases tables listafter deletedatabases setto recoverCodex review items addressed
current_databaseis now stored ascurrent_databases: HashMap<workspace_id, database_id>. Using--workspace-id ws_bwill never pick up a database set underws_a. The footer andX-Database-Idheader both use the workspace that was actually resolved for the command.databases deletenow clears the saved current database when the deleted ID was the active one, preventing subsequent commands from silently sending a staleX-Database-Id.🤖 Generated with Claude Code