Service instance generation (ARCHITECTURE §5.1): for each active
service, plan instances in the rolling window and upsert on
(service_id, starts_at). onConflictDoNothing makes the whole thing
idempotent — a re-run creates 0 rows, cancelled/published instances
are never touched, past instances are never deleted.
- src/domain/instances.ts: pure planInstances() + windowTarget();
DST-safe instants via localToUtc, no DB imports.
- src/domain/instances.test.ts: 7 tests (window boundary, DST-safe
instants, determinism, biweekly phase, monthly-nth, windowTarget).
- src/db/instances.ts: generateInstances() idempotent upsert;
occurs_on stored as zoned midnight (no UTC-midnight shift).
- src/app/api/dev/cron/instances/route.ts: GET drives the daily job.
No schema change (service_instances unique index predates this unit;
slot materialization stays deferred to D3). Verified: run twice ->
0 created, count unchanged; published instances byte-identical;
generated instances stored as DST-safe UTC instants.