fix(db): add SetNull cascade on Assignment→DemandRequirement + composite indexes
Prevents orphaned Assignment rows when a DemandRequirement is deleted. Adds (resourceId, status, endDate) and (projectId, status, endDate) indexes to support capacity range queries. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
-- Migration: Add SetNull cascade on Assignment → DemandRequirement FK
|
||||
-- When a DemandRequirement is deleted, assignments lose their reference but are not deleted.
|
||||
|
||||
ALTER TABLE "assignments" DROP CONSTRAINT IF EXISTS "assignments_demandRequirementId_fkey";
|
||||
ALTER TABLE "assignments" ADD CONSTRAINT "assignments_demandRequirementId_fkey"
|
||||
FOREIGN KEY ("demandRequirementId") REFERENCES "demand_requirements"("id")
|
||||
ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
Reference in New Issue
Block a user