feat(db): extract agents + provider-state aggregates to Drizzle (#844) #864

Merged
code-lead merged 1 commit from code-lead/844 into main 2026-05-04 22:56:06 +00:00
Collaborator

Splits the agents, agent_provider_state, and agent_provider_events CRUD blocks out of the db.ts god-file into per-aggregate Drizzle modules. The registerOnAgentDelete lifecycle hook is preserved verbatim so domain/agent/provider-failover.ts keeps scrubbing its in-memory 5xx sliding window on instance delete.

schema/agents.ts declares match_labels / plugins as text({ mode: "json" }).$type<string[]>(); the public AgentRow shape keeps the raw JSON-string form so the resolver layer (deferred to #845) doesn't break. Tri-state plugins semantics are documented in the schema file. notes stays plain text() — free-form operator text, JSON encoding adds nothing.

Closes #844

Test plan

  • bun x turbo run typecheck clean across all 5 workspaces
  • bun x @biomejs/biome@^2 format . no diff (3 lint warnings are pre-existing on main)
  • bun run apps/server/scripts/db-check.ts — agents + tasks both ok
  • Full bun test — 3137 pass / 0 fail across 137 files
  • New agents-store.test.ts (45 tests) + agent-provider.test.ts (10 tests) cover CRUD, hook contract, and cascade
Splits the `agents`, `agent_provider_state`, and `agent_provider_events` CRUD blocks out of the `db.ts` god-file into per-aggregate Drizzle modules. The `registerOnAgentDelete` lifecycle hook is preserved verbatim so `domain/agent/provider-failover.ts` keeps scrubbing its in-memory 5xx sliding window on instance delete. `schema/agents.ts` declares `match_labels` / `plugins` as `text({ mode: "json" }).$type<string[]>()`; the public `AgentRow` shape keeps the raw JSON-string form so the resolver layer (deferred to #845) doesn't break. Tri-state `plugins` semantics are documented in the schema file. `notes` stays plain `text()` — free-form operator text, JSON encoding adds nothing. Closes #844 ## Test plan - [x] `bun x turbo run typecheck` clean across all 5 workspaces - [x] `bun x @biomejs/biome@^2 format .` no diff (3 lint warnings are pre-existing on main) - [x] `bun run apps/server/scripts/db-check.ts` — agents + tasks both `ok` - [x] Full `bun test` — 3137 pass / 0 fail across 137 files - [x] New `agents-store.test.ts` (45 tests) + `agent-provider.test.ts` (10 tests) cover CRUD, hook contract, and cascade
feat(db): extract agents + provider-state aggregates to Drizzle (#844)
All checks were successful
qa / dockerfile (pull_request) Successful in 17s
qa / db-schema (pull_request) Successful in 27s
qa / qa-1 (pull_request) Successful in 1m25s
qa / qa (pull_request) Successful in 0s
f3a43cc424
Splits the `agents`, `agent_provider_state`, and `agent_provider_events`
CRUD blocks out of the `db.ts` god-file into per-aggregate Drizzle
modules. The `registerOnAgentDelete` lifecycle hook is preserved
verbatim so `domain/agent/provider-failover.ts` can keep scrubbing its
in-memory 5xx sliding window on instance delete.

`schema/agents.ts` declares `match_labels` / `plugins` as
`text({ mode: "json" }).$type<string[]>()`; the public `AgentRow` shape
keeps the raw JSON-string form so the resolver layer (deferred to #845)
doesn't break. Tri-state `plugins` semantics (NULL = inherit, [] = empty
override, array = explicit list) are documented in the schema file.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
reviewer approved these changes 2026-05-04 22:50:37 +00:00
reviewer left a comment

Extraction clean — all ~23 functions moved to agents-store.ts / agent-provider.ts, callers updated, registerOnAgentDelete hook contract preserved verbatim, Drizzle schemas match the SQL init. decodeAgentRow re-stringify is intentional and correct. 55 new tests cover CRUD, tri-state plugins, cascade, and hook-fires-once. CI green.

Extraction clean — all ~23 functions moved to `agents-store.ts` / `agent-provider.ts`, callers updated, `registerOnAgentDelete` hook contract preserved verbatim, Drizzle schemas match the SQL init. `decodeAgentRow` re-stringify is intentional and correct. 55 new tests cover CRUD, tri-state plugins, cascade, and hook-fires-once. CI green.
Collaborator

PR has conflicts — please rebase on main before merging.

PR has conflicts — please rebase on main before merging.
code-lead force-pushed code-lead/844 from f3a43cc424
All checks were successful
qa / dockerfile (pull_request) Successful in 17s
qa / db-schema (pull_request) Successful in 27s
qa / qa-1 (pull_request) Successful in 1m25s
qa / qa (pull_request) Successful in 0s
to f58707441f
All checks were successful
qa / sql-layer-check (pull_request) Successful in 23s
qa / dockerfile (pull_request) Successful in 25s
qa / db-schema (pull_request) Successful in 28s
qa / qa-1 (pull_request) Successful in 1m55s
qa / qa (pull_request) Successful in 0s
2026-05-04 22:54:05 +00:00
Compare
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
charles/claude-hooks!864
No description provided.