Skip to content

Commit 4aa96bb

Browse files
Juwang110claude
andcommitted
Restrict deleting a coordinator who still has assigned volunteers
The old single-column FK blocked this; keep that behavior on the join table instead of cascading the assignments away. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d196763 commit 4aa96bb

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎apps/backend/src/coordinators/coordinators.entity.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export class FosterCoordinator {
3636
@ManyToMany(
3737
() => FosterVolunteer,
3838
(volunteer) => volunteer.assignedCoordinators,
39+
// Matches the migration: a coordinator with assigned volunteers can't be deleted.
40+
{ onDelete: 'RESTRICT' },
3941
)
4042
assignedVolunteers!: FosterVolunteer[];
4143
}

‎apps/backend/src/migrations/1791100000000-ReplaceAssignedCoordinatorWithJoinTable.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ export class ReplaceAssignedCoordinatorWithJoinTable1791100000000
1717
CONSTRAINT "fk_assignment_coordinator"
1818
FOREIGN KEY ("coordinator_id")
1919
REFERENCES "foster_coordinators" ("coordinator_id")
20-
ON DELETE CASCADE
20+
ON DELETE RESTRICT
2121
)
2222
`);
2323

24-
// The composite PK leads with volunteer_id, so lookups and cascades by
25-
// coordinator need their own index.
24+
// Deleting a coordinator who still has volunteers is blocked, as it was with
25+
// the old single-column FK. The composite PK leads with volunteer_id, so
26+
// lookups and that delete check by coordinator need their own index.
2627
await queryRunner.query(`
2728
CREATE INDEX "idx_volunteer_coordinator_assignments_coordinator_id"
2829
ON "volunteer_coordinator_assignments" ("coordinator_id")

0 commit comments

Comments
 (0)