Extract + Drizzle flows aggregate (flows + runs + audit + legacy_forge_calls) #843

Closed
opened 2026-05-04 20:28:47 +00:00 by claude-desktop · 1 comment
Collaborator

As a maintainer, I want all flow-related tables (flows, flow_runs, flow_node_runs, flow_audit, legacy_forge_calls) split out and rewritten on Drizzle, so that the largest SQL surface in db.ts (~25 fns) lives in one cohesive module with type-safe queries.

Acceptance criteria

Extraction

  • flows.ts + flow-runs.ts + flow-audit.ts + legacy-forge-calls.ts (split by table for review-ability).
  • All ~25 fns moved (audit db.ts:1571-1953 for exhaustive list): listFlows, getFlow, upsertFlow, seedDefaultFlow, deleteFlow, insertFlowRun, finishFlowRun, getFlowRun, listFlowRuns, deleteFlowRun, pruneFlowRunsOlderThan, insertFlowNodeRun, listFlowNodeRuns, listFlowNodeIntentsSince, insertFlowAudit, listFlowAudit, getFlowAuditByVersion, withFlowTransaction, insertLegacyForgeCall, listLegacyForgeCallsSince, resetLegacyForgeCalls.

Transactions

  • withFlowTransaction(fn) keeps same signature; internally wraps Drizzle + raw via shared getDb().transaction(...) so other-aggregate raw SQL inside the closure still participates.

Drizzle

  • schema/flows.ts + schema/flow-runs.ts + schema/flow-audit.ts + schema/legacy-forge-calls.ts.
  • All fns rewritten.

Tests

  • flows-db.test.ts green.
  • Cross-aggregate transaction test: open withFlowTransaction, write to flows (Drizzle) + holds (Drizzle from #840) + still-raw aggregate, rollback, all changes reverted.

Out of scope

  • Flow-runner business logic (domain/flows/) — only DB layer changes.

References

  • apps/server/src/infrastructure/database/db.ts:1571-1953.
  • apps/server/src/domain/flows/flow-dispatch.ts (caller).
  • Foundation story (#839) must merge first.
**As a** maintainer, **I want** all flow-related tables (`flows`, `flow_runs`, `flow_node_runs`, `flow_audit`, `legacy_forge_calls`) split out and rewritten on Drizzle, **so that** the largest SQL surface in `db.ts` (~25 fns) lives in one cohesive module with type-safe queries. ## Acceptance criteria ### Extraction - [ ] `flows.ts` + `flow-runs.ts` + `flow-audit.ts` + `legacy-forge-calls.ts` (split by table for review-ability). - [ ] All ~25 fns moved (audit `db.ts:1571-1953` for exhaustive list): `listFlows`, `getFlow`, `upsertFlow`, `seedDefaultFlow`, `deleteFlow`, `insertFlowRun`, `finishFlowRun`, `getFlowRun`, `listFlowRuns`, `deleteFlowRun`, `pruneFlowRunsOlderThan`, `insertFlowNodeRun`, `listFlowNodeRuns`, `listFlowNodeIntentsSince`, `insertFlowAudit`, `listFlowAudit`, `getFlowAuditByVersion`, `withFlowTransaction`, `insertLegacyForgeCall`, `listLegacyForgeCallsSince`, `resetLegacyForgeCalls`. ### Transactions - [ ] `withFlowTransaction(fn)` keeps same signature; internally wraps Drizzle + raw via shared `getDb().transaction(...)` so other-aggregate raw SQL inside the closure still participates. ### Drizzle - [ ] `schema/flows.ts` + `schema/flow-runs.ts` + `schema/flow-audit.ts` + `schema/legacy-forge-calls.ts`. - [ ] All fns rewritten. ### Tests - [ ] `flows-db.test.ts` green. - [ ] Cross-aggregate transaction test: open `withFlowTransaction`, write to flows (Drizzle) + holds (Drizzle from #840) + still-raw aggregate, rollback, all changes reverted. ## Out of scope - Flow-runner business logic (`domain/flows/`) — only DB layer changes. ## References - `apps/server/src/infrastructure/database/db.ts:1571-1953`. - `apps/server/src/domain/flows/flow-dispatch.ts` (caller). - Foundation story (#839) must merge first.
Collaborator

🤖 Auto-assigned to code-lead (heuristic: default → code-lead (no specific label match; safer than code)). Reply /unassign to reroute.

🤖 Auto-assigned to **code-lead** (heuristic: default → code-lead (no specific label match; safer than code)). Reply `/unassign` to reroute.
Sign in to join this conversation.
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.

Reference
charles/claude-hooks#843
No description provided.