Skip to content

feat: database with configuration#194

Merged
sergiofilhowz merged 3 commits into
mainfrom
feat/database-with-configuration
May 28, 2026
Merged

feat: database with configuration#194
sergiofilhowz merged 3 commits into
mainfrom
feat/database-with-configuration

Conversation

@sergiofilhowz

@sergiofilhowz sergiofilhowz commented May 27, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Database worker now supports runtime configuration management with automatic connection pool hot-reload on configuration changes
    • Added reactive database triggers for PostgreSQL
  • Documentation

    • Expanded comprehensive database skill documentation covering API references, usage patterns, and driver-specific behaviors
    • Enhanced configuration guides for setup and runtime management

Review Change Stack

@vercel

vercel Bot commented May 27, 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 May 27, 2026 9:00pm

Request Review

@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@sergiofilhowz, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 34 minutes and 52 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cd999969-f95e-4d1b-9bc3-3c4d1082ac8e

📥 Commits

Reviewing files that changed from the base of the PR and between 212b7b5 and 649995c.

📒 Files selected for processing (4)
  • database/src/config.rs
  • database/src/configuration.rs
  • database/src/main.rs
  • database/tests/integration.rs
📝 Walkthrough

Walkthrough

This pull request transitions the database worker from file-based configuration to runtime configuration management. The configuration worker now manages database settings with hot-reloading, while connection pools transition to async access via Arc<RwLock<HashMap>>. E2E testing receives a new TypeScript seeding mechanism, and documentation reflects the updated architecture.

Changes

Database Configuration Architecture

Layer / File(s) Summary
Configuration types and JSON schema support
database/src/config.rs
WorkerConfig, DatabaseConfig, PoolConfig, TlsConfig, and TlsMode gain Serialize/JsonSchema derives. New public APIs (from_json, to_json, json_schema) enable JSON serialization; DatabaseConfig.driver is skipped in serialized output. Test suite expanded with JSON roundtrip and schema-shape assertions.
Configuration registration and pool management
database/src/configuration.rs
New module handles schema registration (optionally seeded), fetches live configuration via RPC, builds connection pools per database, applies hot-reloaded pools to AppState under write lock, and wires a configuration-change trigger with bounded retry logic and backoff.
AppState async pool access via RwLock
database/src/handlers/mod.rs, database/src/handlers/*.rs
AppState.pools changed from Arc<HashMap> to Arc<RwLock<HashMap>>; .pool() accessor converted from synchronous borrowed-reference lookup to async method acquiring read lock and returning cloned Pool. All handler callsites updated to await async pool acquisition. Test fixtures across all handlers updated to construct pools with RwLock wrapper.
Worker initialization and module wiring
database/src/main.rs, database/src/lib.rs
Worker entrypoint refactored to optional --config seed source, delegating pool construction to configuration module. Configuration-change trigger registered alongside row-change trigger. Public module renamed configconfiguration. Startup now calls register_configfetch_configbuild_pools sequence.
E2E test configuration seeding and schema
database/tests/e2e/workers/harness/src/seed-configuration.ts, database-config.ts, fixtures/database.schema.json
New TypeScript seeding script registers database config schema and initial value via configuration::register with retry logic. database-config.ts exports configuration constants for sqlite/postgres/mysql. JSON schema fixture validates configuration shape.
E2E test runner orchestration
database/tests/e2e/run-tests.sh
Test runner manages database worker as separate host process, tracks DATABASE_PID, clears data/configuration on reset, seeds database config before worker startup, waits for database::query health check, and extends cleanup to kill database worker on exit.
Documentation updates and examples
database/README.md, database/skills/SKILL.md, database/config.yaml.example, database/tests/e2e/README.md, database/tests/integration.rs
README and SKILL.md updated to describe configuration-worker pattern, hot-reload semantics, and driver selection. Config examples restructured to top-level databases shape. E2E README expanded with startup sequence, component layout, and troubleshooting. Integration tests updated to use RwLock-wrapped pools.
CI and workflow updates
.github/workflows/database-e2e.yml
Engine installer invoked with --next channel flag to pull from next release branch.

🎯 4 (Complex) | ⏱️ ~75 minutes

Suggested reviewers

  • andersonleal
  • ytallo

🐰 Pools now flow through locks, configurations swim with retries,
Hot reload the schemas while the tests synchronously conspires!
Click, click, the database awakens from its file-based slumber—
Where once was YAML, now RwLock guards the thunder. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.10% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the primary change: introducing configuration management to the database worker, including schema registration, runtime hot-reloading, and the new configuration module integration.
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/database-with-configuration

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.

@github-actions

github-actions Bot commented May 27, 2026

Copy link
Copy Markdown
Contributor

skill-check — worker

0 verified, 13 skipped (no docs/).

Layer Result
structure
vale
ai

Three for three. Nicely done.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/database-e2e.yml:
- Around line 46-49: The CI step that runs the installer uses the flag "--next"
(see the "Install iii engine (next)" step and the curl ... | sh -s -- --next
invocation) which pulls a moving pre-release; replace the dynamic "--next" flag
with a pinned release tag string (e.g., "--version vX.Y.Z" or the specific
pre-release "--version vX.Y.Z-next.1" depending on desired stability) so the
workflow installs a reproducible engine version; update the step name
accordingly if needed.

In `@database/skills/SKILL.md`:
- Around line 94-95: The SKILL.md entry for database::row-change and the README
disagree about v1.0.0 behavior; decide whether v1.0.0 should (A) return
UNSUPPORTED from registerTrigger or (B) succeed on setup (slot/publication) but
stub streaming. Update the SKILL.md text around database::row-change and the
registerTrigger description to match the chosen contract, referencing the
registerTrigger symbol and the database::row-change capability so both docs
consistently state the same behavior (either explicit UNSUPPORTED return or
“setup succeeds, streaming stubbed”) and include any notes about pending
tokio-postgres replication API availability.

In `@database/src/config.rs`:
- Around line 12-15: This file fails rustfmt checks due to import ordering and
line-wrapping around long schema/test assertion lines; run rustfmt to reflow
imports and wrap long lines (e.g., the use statements like use
schemars::JsonSchema, use schemars::schema::Schema, use serde::{Deserialize,
Serialize}, use serde_json::{json, Value}) and the long blocks around the
schema/test assertions (also at the regions corresponding to lines 229-237 and
410-456) by running cargo fmt --all (or cargo fmt --all -- --check to verify)
and commit the formatted output.

In `@database/src/configuration.rs`:
- Around line 7-9: Run rustfmt on this module (configuration.rs) and reformat
the imports and wrapped function/signature lines so they comply with cargo fmt
--check; specifically tidy the use group containing III, IIIError,
RegisterFunction, RegisterTriggerInput, TriggerRequest and fix wrapping for the
affected function signatures and call sites (areas around the
RegisterFunction/RegisterTriggerInput/TriggerRequest usages and the long blocks
later in the file) so the import grouping and line wrapping conform to rustfmt
rules, then re-commit the formatted file.

In `@database/src/main.rs`:
- Around line 22-24: The multi-line use import for iii_sdk is failing rustfmt;
change the import to rustfmt-preferred grouping by placing the items inside a
single braced list (i.e., use iii_sdk::{register_worker, InitOptions,
RegisterFunction, RegisterTriggerType};) so that the symbols register_worker,
InitOptions, RegisterFunction, and RegisterTriggerType are formatted as a single
grouped import instead of the current broken multi-line form.

In `@database/tests/e2e/workers/harness/fixtures/database.schema.json`:
- Around line 152-173: The root JSON schema is missing a required declaration
for the "databases" property so an empty object {} can still validate; update
database.schema.json to add a root "required" array that includes "databases"
(so the existing "databases" definition with "minProperties":1 is enforced) —
locate the top-level schema object in database.schema.json and add "required":
["databases"] alongside the existing "properties" entry.

In `@database/tests/integration.rs`:
- Around line 42-45: The assertion block comparing
from_yaml.databases["primary"].driver and from_json.databases["primary"].driver
is failing rustfmt; reformat this assertion to comply with rustfmt (either
collapse to a single-line assert_eq! or let rustfmt reflow the multiline form)
and then run cargo fmt --all to apply the style changes; ensure the identifiers
from_yaml, from_json, databases, and driver remain unchanged so the assertion
logic is preserved.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f6390dcb-096b-4ade-96cc-e52fef6a97e7

📥 Commits

Reviewing files that changed from the base of the PR and between 61bf391 and 212b7b5.

📒 Files selected for processing (33)
  • .github/workflows/database-e2e.yml
  • database/README.md
  • database/config.yaml
  • database/config.yaml.example
  • database/skills/SKILL.md
  • database/skills/iii-database/execute.md
  • database/skills/iii-database/interactive-transaction.md
  • database/skills/iii-database/prepared-statements.md
  • database/skills/iii-database/query.md
  • database/skills/iii-database/transaction.md
  • database/skills/index.md
  • database/src/config.rs
  • database/src/configuration.rs
  • database/src/handlers/begin_transaction.rs
  • database/src/handlers/commit_transaction.rs
  • database/src/handlers/execute.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/lib.rs
  • database/src/main.rs
  • database/tests/e2e/README.md
  • database/tests/e2e/config.yaml
  • database/tests/e2e/run-tests.sh
  • database/tests/e2e/workers/harness/fixtures/database.schema.json
  • database/tests/e2e/workers/harness/package.json
  • database/tests/e2e/workers/harness/src/database-config.ts
  • database/tests/e2e/workers/harness/src/seed-configuration.ts
  • database/tests/integration.rs
💤 Files with no reviewable changes (7)
  • database/skills/iii-database/execute.md
  • database/config.yaml
  • database/skills/iii-database/query.md
  • database/skills/iii-database/transaction.md
  • database/skills/iii-database/prepared-statements.md
  • database/skills/index.md
  • database/skills/iii-database/interactive-transaction.md

Comment on lines +46 to +49
- name: Install iii engine (next)
run: |
curl -fsSL --retry 3 --retry-connrefused --retry-delay 5 \
https://install.iii.dev/iii/main/install.sh | sh
https://install.iii.dev/iii/main/install.sh | sh -s -- --next

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

What installation flags does https://install.iii.dev/iii/main/install.sh support for pinning a specific iii engine version, and what is the recommended CI strategy for reproducible installs (exact version vs channel)?

💡 Result:

The iii engine installer script (https://install.iii.dev/iii/main/install.sh) supports these installation “pinning” arguments: 1) Pin an exact engine version - Usage: sh -s -- v0.9.0 (the docs show passing the version argument as vX.Y.Z) [1] - Behavior: when a specific VERSION is requested, the installer rejects prerelease versions (it checks the GitHub release JSON’s prerelease field, and errors if prerelease == true) [2] 2) Install “latest stable” (channel behavior) - Default behavior (no -v / version argument): the script “installing latest version” [2] - Under the hood: for latest-version selection it probes GitHub’s /releases/latest first, and only accepts a tag that matches the expected prefix (iii/v*) and is non-draft/non-prerelease; if that fails, it falls back to listing releases and filtering by prerelease==false and tag_name prefix iii/v* [2] So, for pinning reproducibly, prefer exact version pinning (e.g., v0.9.0) over “channel/latest” resolution [1][2]. Recommended CI strategy for reproducible installs (exact version vs channel) - Recommended: pin an exact version (e.g., use -v vX.Y.Z / pass vX.Y.Z as the version argument) in CI, not the moving “latest”/channel behavior, because “latest” is resolved at install time by querying GitHub releases/latest and filtering [2]. - Additionally, do not use prerelease channels in CI: the engine installer explicitly rejects prereleases even when a specific version is requested (“version $VERSION is a prerelease — use a stable release”) [2]. If you want stronger reproducibility than “install a single binary version,” use the project’s lockfile workflow for registry-managed workers: commit iii.lock with config.yaml and replay with iii worker sync so CI/dev/deploy environments install/repair the same pinned set (and the sync step verifies binaries by SHA-256 before activation) [3].

Citations:


🌐 Web query:

What does the iii engine installer script https://install.iii.dev/iii/main/install.sh interpret the --next flag as (prerelease/next channel vs something else), and how should CI handle it for reproducible installs?

💡 Result:

The --next flag in the iii engine installer script (https://install.iii.dev/iii/main/install.sh) directs the script to fetch and install the latest pre-release version of the iii engine [1]. Specifically, it triggers logic that queries GitHub releases for tags matching the -next. pattern (such as iii/v*-next.*) [1][2], rather than defaulting to the latest stable release [1][3]. How CI Should Handle It for Reproducible Installs: Because --next fetches the latest available pre-release dynamically, it is inherently non-deterministic and unsuitable for reproducible CI environments [1]. To ensure reproducibility in CI/CD pipelines, you should pin the engine to a specific version instead of using the --next flag [4][5]. 1. Pin to a Specific Version: Use the script's ability to accept a version argument directly. By providing a specific tag, you ensure the installer fetches a known, immutable release [4][5]. Example: curl -fsSL https://install.iii.dev/iii/main/install.sh | sh -s -- v0.12.0 2. Avoid --next in Production CI: The --next flag is intended for "work-in-progress" (WIP) testing and development environments where tracking the cutting edge is desired [1]. If you must test pre-release builds, pin to a specific pre-release tag (e.g., v0.12.0-next.1) rather than using the generic --next flag to avoid unexpected breaking changes between CI runs [1][2]. 3. Verify Dependencies: Ensure your CI environment validates the checksum or version of the installed binary to prevent supply chain drift [6][3]. Since the installer script itself can evolve [7][2], pinning the version and potentially caching the installer script or the downloaded binary are best practices for maintaining a locked environment [4].

Citations:


Pin iii engine to a specific release in CI (avoid --next)
In .github/workflows/database-e2e.yml, --next installs the latest pre-release dynamically (e.g., matching *-next.*), making E2E runs non-reproducible and prone to unexpected breakage. Pin an exact stable engine version (e.g., vX.Y.Z), or if you need WIP, pin a specific pre-release tag (e.g., vX.Y.Z-next.1) instead of using --next.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/database-e2e.yml around lines 46 - 49, The CI step that
runs the installer uses the flag "--next" (see the "Install iii engine (next)"
step and the curl ... | sh -s -- --next invocation) which pulls a moving
pre-release; replace the dynamic "--next" flag with a pinned release tag string
(e.g., "--version vX.Y.Z" or the specific pre-release "--version vX.Y.Z-next.1"
depending on desired stability) so the workflow installs a reproducible engine
version; update the step name accordingly if needed.

Comment thread database/skills/SKILL.md
Comment on lines +94 to +95
- You need events today — v1.0.0 returns `UNSUPPORTED` on `registerTrigger`
pending an upstream `tokio-postgres` replication API release.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Conflicting database::row-change behavior description.

Line 94 states registerTrigger returns UNSUPPORTED, but the main README describes v1.0.0 as setup-only (slot/publication creation succeeds; streaming is stubbed). Please align both docs to one behavior contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@database/skills/SKILL.md` around lines 94 - 95, The SKILL.md entry for
database::row-change and the README disagree about v1.0.0 behavior; decide
whether v1.0.0 should (A) return UNSUPPORTED from registerTrigger or (B) succeed
on setup (slot/publication) but stub streaming. Update the SKILL.md text around
database::row-change and the registerTrigger description to match the chosen
contract, referencing the registerTrigger symbol and the database::row-change
capability so both docs consistently state the same behavior (either explicit
UNSUPPORTED return or “setup succeeds, streaming stubbed”) and include any notes
about pending tokio-postgres replication API availability.

Comment thread database/src/config.rs Outdated
Comment thread database/src/configuration.rs Outdated
Comment thread database/src/main.rs Outdated
Comment thread database/tests/e2e/workers/harness/fixtures/database.schema.json
Comment thread database/tests/integration.rs
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