unit(D3): slot materialization (headcount, call time)

Slot materialization (ARCHITECTURE §5.2): for each non-published
instance, plan the seats planSlots() computes and upsert them on
(service_instance_id, role_id, slot_index). onConflictDoNothing makes
it idempotent; published weeks are skipped (owned by the publish flow).

- src/domain/slots.ts: pure planSlots()/planSlotsForRole(); headcount
  fills slotIndex 1..N, call_time = start + offset (null if no offset).
- src/domain/slots.test.ts: 5 tests (Audio headcount 2 -> 2 slots with
  correct call_time, clamp to 1, null offset, multi-role flatten).
- src/db/slots.ts: materializeSlotsForInstance() + materializeSlots().
- src/app/api/dev/cron/slots/route.ts: GET drives the daily job.

No schema change (slots unique index predates this unit; position_skills
stays deferred to D5). Verified: draft instance + Audio headcount 2 ->
4 seats (Audio x2 + Livestream + Slides), Audio call_time 09:30 EST;
re-run creates 0 rows. Seed restored to canonical 4 instances / 12
slots after testing.
This commit is contained in:
Tiel Coder
2026-11-18 05:27:36 +00:00
parent 8fb6459b0d
commit 8ee339b235
5 changed files with 236 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
import { materializeSlots } from "@/db/slots";
/**
* Slot materialization (ARCHITECTURE §5.2). Drives `materializeSlots()` —
* idempotent on (instance, role, seat). Re-runs create 0 rows.
*
* GET /api/dev/cron/slots
*/
export const GET = async () => {
const result = await materializeSlots();
return new Response(JSON.stringify({ result }), {
status: 200,
headers: { "content-type": "application/json" },
});
};