From b625090c6324c7455824df63ab5fedec7d2f97f7 Mon Sep 17 00:00:00 2001 From: Julien Gautier Date: Tue, 26 May 2026 11:56:47 +0200 Subject: [PATCH] fix(structures): align Structure.delegation_code FK action with Prisma default ON DELETE RESTRICT was Prisma's default for required relations; Structure.delegation is optional (`Delegation?`), so the matching default is ON DELETE SET NULL. Mismatch caused `prisma migrate dev` to detect drift and prompt for a corrective migration on every run. Caught locally on first VM-side validation. No production deployment of #228 yet, so editing the migration in place rather than shipping a corrective sibling - keeps the repo's migration history minimal. Inline comment at the offending line explains the rule (nullable Prisma relation -> SET NULL) to head off the same mistake when ADR-0026 PR 1 adds optional FKs (Person.user, User.scopes). --- .../20260526143000_add_org_hierarchy/migration.sql | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/portal-bff/prisma/migrations/20260526143000_add_org_hierarchy/migration.sql b/apps/portal-bff/prisma/migrations/20260526143000_add_org_hierarchy/migration.sql index 49c5cc2..ffe4372 100644 --- a/apps/portal-bff/prisma/migrations/20260526143000_add_org_hierarchy/migration.sql +++ b/apps/portal-bff/prisma/migrations/20260526143000_add_org_hierarchy/migration.sql @@ -83,9 +83,13 @@ ALTER TABLE "delegations" ADD CONSTRAINT "delegations_region_code_fkey" ON DELETE RESTRICT ON UPDATE CASCADE; -- AddForeignKey +-- ON DELETE SET NULL because delegationCode is optional in the Prisma +-- schema (Structure.delegation Delegation?). Matches Prisma's default +-- for nullable relations; the drift gate would otherwise flag this +-- on every `prisma migrate dev`. ALTER TABLE "structures" ADD CONSTRAINT "structures_delegation_code_fkey" FOREIGN KEY ("delegation_code") REFERENCES "delegations"("code") - ON DELETE RESTRICT ON UPDATE CASCADE; + ON DELETE SET NULL ON UPDATE CASCADE; -- ------------------------------------------------------------------ -- Test-tenant reference seed (per ADR-0027 ยง"Seeding posture"). -- 2.30.2