Files
support_backend/prisma/migrations/20260909120000_add_concurrency_guards/migration.sql
T
saqib mirandClaude Sonnet 5 1e332143bd build(016-load-concurrency-testing): T001-T002 setup + concurrency-guard migration
Adds autocannon as a devDependency for the load-test tooling (T001), and the
shared schema migration T002 blocks: SLARun.version for optimistic
concurrency, plus two Postgres partial unique indexes
(assignments_one_current_per_ticket, escalation_events_ticket_rule_unique)
guarding against the assignment and escalation races research.md documents.
Applied directly to both the real dev DB and the throwaway test DB.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-09 17:03:37 +05:30

14 lines
932 B
SQL

-- AlterTable
ALTER TABLE "sla_runs" ADD COLUMN "version" INTEGER NOT NULL DEFAULT 0;
-- 016-load-concurrency-testing research.md §1: at most one current assignment per ticket,
-- enforced at the database level (a partial unique index, since Prisma's schema DSL cannot
-- express a WHERE-predicated unique constraint directly).
CREATE UNIQUE INDEX "assignments_one_current_per_ticket" ON "assignments"("ticketId") WHERE "isCurrent" = true;
-- 016-load-concurrency-testing research.md §3: a given escalation rule may fire at most once
-- per ticket over that ticket's lifetime (SLARun.ticketId is already @unique — no reopen-cycle
-- support, so a rule-triggered breach genuinely cannot recur for the same ticket). Manual
-- escalations (rule_id IS NULL) are excluded and remain repeatable.
CREATE UNIQUE INDEX "escalation_events_ticket_rule_unique" ON "escalation_events"("ticketId", "ruleId") WHERE "ruleId" IS NOT NULL;