Skip to content

feat(database): add listDatabases function to list configured databases#226

Merged
andersonleal merged 1 commit into
mainfrom
feat/database-list-databases
Jun 4, 2026
Merged

feat(database): add listDatabases function to list configured databases#226
andersonleal merged 1 commit into
mainfrom
feat/database-list-databases

Conversation

@andersonleal

@andersonleal andersonleal commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds database::listDatabases — the worker's 12th function — so callers can discover which databases are configured without access to the raw config. Returns config details only (no health checks, no live pool stats):

{
  "databases": [
    {
      "name": "primary",
      "driver": "sqlite",
      "url": "sqlite::memory:",
      "pool": { "max": 10, "idle_timeout_ms": 30000, "acquire_timeout_ms": 5000 },
      "tls": { "mode": "require", "ca_cert_present": false, "trust_native": true }
    }
  ],
  "count": 1
}

Design notes

  • AppState gains a live config snapshot (Arc<RwLock<WorkerConfig>>). Built pools discard their config at build time, so the handler needs this to report details. apply_config now swaps pools and snapshot inside one critical section — a concurrent listDatabases can never observe new pools paired with stale config (and a failed rebuild leaves both untouched, preserving the existing keep-previous-pools contract).
  • No credential leaks: connection URLs pass through the existing config::redact_url (password stripped, username → ***); ca_cert is reported as a presence boolean only, never the filesystem path.
  • Reuses existing utilities: redact_url, transaction::driver_system, and TlsMode's existing kebab-case serialization — no new dependencies.
  • Entries sorted by name for deterministic output; envelope { items, count } mirrors shell::list.

Test plan

  • 7 new unit tests: config defaults, postgres/mysql password redaction, sqlite URL passthrough, deterministic sort + count, TLS overrides without cert-path leak, response envelope shape
  • 2 new integration tests: list_databases_reports_configured_primary and apply_config_updates_list_snapshot (hot-reload regression guard)
  • Full suite green: 193 lib + 5 integration + 3 value-coercion tests
  • cargo llvm-cov: 100% line/region/function coverage on the new handler; apply_config fully covered
  • cargo fmt --all clean
  • Live smoke test against a running engine: iii trigger database::listDatabases '{}'

Summary by CodeRabbit

  • New Features

    • Added database::listDatabases API endpoint to list all configured databases with metadata including driver type, connection pool configuration, and TLS settings.
  • Documentation

    • Updated function reference documentation to include the new listDatabases operation.

Add `database::listDatabases` returning config details for every
configured database: logical name, driver (postgres/mysql/sqlite),
credential-redacted connection URL, pool settings, and TLS mode.
Config-only by design — no health checks or live pool statistics.

- Extend AppState with a live `config` snapshot, swapped together with
  pools inside apply_config's critical section so hot-reload never
  exposes new pools paired with stale config
- Reuse existing config::redact_url and transaction::driver_system;
  report ca_cert as a presence boolean to avoid leaking paths
- Sort entries by name for deterministic output
- 7 unit tests (redaction, TLS path-leak guard, sort/count, envelope)
  plus 2 integration tests including a hot-reload snapshot guard
- Document the function in README and skills/SKILL.md
@vercel

vercel Bot commented Jun 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
workers Ready Ready Preview, Comment Jun 4, 2026 5:43pm

Request Review

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

skill-check — worker

0 verified, 14 skipped (no docs/).

Layer Result
structure
vale
ai
render

Four for four. Nicely done.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 44db96ef-d702-4986-8a84-cc5b70ef72ad

📥 Commits

Reviewing files that changed from the base of the PR and between 84871c4 and 0902360.

⛔ Files ignored due to path filters (1)
  • database/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (16)
  • database/README.md
  • database/skills/SKILL.md
  • database/src/configuration.rs
  • database/src/handlers/begin_transaction.rs
  • database/src/handlers/commit_transaction.rs
  • database/src/handlers/execute.rs
  • database/src/handlers/list_databases.rs
  • database/src/handlers/mod.rs
  • database/src/handlers/prepare.rs
  • database/src/handlers/query.rs
  • database/src/handlers/rollback_transaction.rs
  • database/src/handlers/run_statement.rs
  • database/src/handlers/transaction.rs
  • database/src/handlers/transaction_execute.rs
  • database/src/main.rs
  • database/tests/integration.rs

📝 Walkthrough

Walkthrough

This PR adds a new database::listDatabases RPC handler that exposes configured database metadata to callers. The handler reads from a new AppState.config field that stores a snapshot of the current database configuration, which is atomically updated alongside connection pools during configuration reloads.

Changes

Database List Handler

Layer / File(s) Summary
AppState configuration field and atomic state management
database/src/handlers/mod.rs, database/src/configuration.rs
AppState gains a new config: Arc<RwLock<WorkerConfig>> field to store the current database configuration snapshot. apply_config is updated to atomically acquire both the pools and config write locks in order, then assign the newly built pools and new config snapshot within that coordinated critical section.
List databases handler implementation
database/src/handlers/list_databases.rs
Introduces ListDatabasesReq, DatabaseInfo, PoolInfo, TlsInfo, and ListDatabasesResp types. The handle function reads configured databases, maps driver names, redacts connection credentials via redact_url, converts TLS metadata (exposing CA presence as a boolean rather than a filesystem path), sorts databases by name for deterministic output, and returns count alongside the list. Includes unit tests validating credential redaction, TLS field masking, and response envelope shape.
Handler registration and wiring
database/src/main.rs, database/src/handlers/mod.rs
Imports list_databases handler module, initializes AppState.config from fetched configuration during startup, registers database::listDatabases as an iii function wired to list_databases::handle, and updates the startup function count from 11 to 12.
Test suite updates
database/src/handlers/*.rs, database/tests/integration.rs
All handler unit test helpers are updated to initialize the new AppState.config field with default WorkerConfig wrapped in Arc<RwLock<_>>. Integration tests verify that list_databases::handle reports the initial configured database and reflects updates after apply_config.
Documentation
database/README.md, database/skills/SKILL.md
README and SKILL.md are updated to document database::listDatabases as a configuration-only listing function that returns database names, drivers, redacted URLs, pool settings, and TLS metadata without performing health checks or reporting live pool statistics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • iii-hq/workers#194: Introduced the database configuration hot-reload refactor (configuration module and shared state wiring for pools/config) that this PR builds upon by adding the persistent config snapshot field and atomic dual-lock swapping behavior.

Poem

🐰 A database's secrets now laid bare,
Configuration snapshot we gladly share,
List them all with credentials redacted tight,
Atomic swaps keep the state just right,
No more mysteries in the config night! 🔐

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: a new listDatabases function for listing configured databases, which is the primary feature added across multiple files.
Docstring Coverage ✅ Passed Docstring coverage is 81.48% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/database-list-databases

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@andersonleal andersonleal merged commit 96af922 into main Jun 4, 2026
12 checks passed
@andersonleal andersonleal deleted the feat/database-list-databases branch June 4, 2026 18:11
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.

2 participants