feat(structures): add Region/Delegation/Structure schema + seed (ADR-0027 PR 1) #228

Merged
julien merged 1 commits from feat/adr-0027-pr1-org-hierarchy-schema into main 2026-05-26 11:15:11 +02:00

1 Commits

Author SHA1 Message Date
Julien Gautier 9695c9080b feat(structures): add Region/Delegation/Structure schema + seed (ADR-0027 PR 1)
CI / commits (pull_request) Successful in 3m37s
CI / scan (pull_request) Successful in 3m53s
CI / check (pull_request) Failing after 4m0s
CI / a11y (pull_request) Successful in 3m37s
CI / perf (pull_request) Successful in 8m13s
Schema (Prisma): three new public-schema models per ADR-0027 -
Region (INSEE code PK), Delegation (dept code PK + regionCode FK),
Structure (portal-internal code PK + kind discriminator + nullable
unique finess/siret/codePaie + nullable delegationCode FK).

Migration: hand-written, matches the style of init_audit_schema and
users_directory. DDL + CHECK constraint on Structure.kind mirroring
STRUCTURE_KINDS + indexes + inline seed (Region 75 Nouvelle-Aquitaine,
Delegation 33 Gironde, structures 0330800013 + 0330800021 medico-social
Bordeaux/Merignac + siege APF national). Seed is the minimum the 19
test-tenant personas reference; ADR-0029's cascade sync supersedes it
when it ships.

Catalogue (TypeScript): apps/portal-bff/src/structures/structure-kind.ts
exports STRUCTURE_KINDS as const + StructureKind type union +
isStructureKind type guard. Jest spec covers catalogue content,
type guard, narrowing.

Drift gate: extended to scan property-literal "kind: 'X'" expressions
in files that import from structure-kind.ts. Three-layer defense
in depth for Structure.kind = TS type union + Postgres CHECK +
CI gate. 22 spec tests passing.

No consumer code yet - PrismaScopeResolver that dereferences
Structure.code from UserScope.value lives in ADR-0026 PR 2, which
depends on this PR landing first.

Reviewer heads-up: schema.prisma already has a User model (ADR-0020
user-directory cache); ADR-0026 PR 1 introduces a different User
(UUID PK + Person FK). Naming collision flagged for that PR to
resolve - not touched here.
2026-05-26 11:12:19 +02:00