dow-prod-tracker/scripts
DJP 47a65d6498 Keep Deliverable.status in sync with stage state
Root cause of the mismatch: Deliverable.status is a denormalised
column that was only written at create-time (default NOT_STARTED)
and never refreshed when stages moved. The Projects board read it
live and showed "Not Started" while the pipeline ring + dominant-
stage view correctly showed "at Client Feedback (6/11 stages
complete)".

Fix in two parts:

1. New deliverable-status-service with:
   - computeDeliverableStatus(stageStatuses[]) — pure function with
     the summary rule:
        all stages terminal              → APPROVED
        any IN_REVIEW                    → IN_REVIEW
        any IN_PROGRESS/CHANGES_REQUESTED → IN_PROGRESS
        else                             → NOT_STARTED
     ON_HOLD is producer-managed and never overwritten.
   - recomputeDeliverableStatus(deliverableId, txClient?) —
     executes the rule + writes if different. Accepts an optional
     Prisma tx client so callers can run inside their own
     transaction.

2. Wired into every stage-write path:
   - stage-service.updateStageStatus (single-stage transitions)
   - stage-service bulk transaction (bulkUpdateStages) — dedups
     touched deliverable IDs so we don't recompute twice.
   - stage-transition-service forward + rework (board drag) —
     inline inside the same $transaction so the board bucket is
     correct on the next refetch.

3. Backfill script scripts/recompute-deliverable-statuses.ts —
   one-off sweep to fix existing stale rows:
     npx tsx scripts/recompute-deliverable-statuses.ts
   Run once after deploy.
2026-04-21 19:55:39 -04:00
..
backfill-embeddings.ts Phase 0: fork rebrand from hp-prod-tracker 2026-04-20 18:21:39 -04:00
backfill-org-ids.ts feat: add pipeline stage resolver and organization access control 2026-03-14 22:43:43 -05:00
backup-db.sh Nightly pg_dump backups + admin "Export Full XLSX" button 2026-04-21 16:53:49 -04:00
clean-slate.ts Phase 1: Dow-customized Prisma schema + strip HP-only features 2026-04-20 18:35:14 -04:00
migrate-to-dynamic-pipelines.ts feat: add pipeline stage resolver and organization access control 2026-03-14 22:43:43 -05:00
recompute-deliverable-statuses.ts Keep Deliverable.status in sync with stage state 2026-04-21 19:55:39 -04:00
seed-dates-catalog.ts feat(calendar): implement calendar view with event filtering and detail display 2026-03-12 21:20:11 -05:00
seed-dates.ts feat(calendar): implement calendar view with event filtering and detail display 2026-03-12 21:20:11 -05:00