feat(domain): equine legacy importer (packages/anatomy) + generated official equine sheet seed as draft

This commit is contained in:
bchanot committed 2026-10-09 00:38:48 +02:00
1 parent f4682cdba5
commit 52bfc11553
43 files changed
+18466 -33

No files matched your search

+33 -3
View File
@@ -284,6 +284,36 @@ the decision lands; only the naming one is implemented in this document.
| 6 | Server-side validation and integrity for every publication; the frontend is never a security boundary. | SQL already re-checks references, sizes and species. The full shape check (Zod) moves server-side before community publication: plpgsql shape rules or an Edge Function gate, decided at the community step. |
| 7 | Account deletion handles dependencies and transfers explicitly (RGPD); no dependency may block the erasure of personal data forever. | Retention step (§16): published versions get their `created_by` / `published_by` anonymised through a dedicated system path (the immutability guard will allow that single transition), personal sheets are transferred or archived, `creator_user_id` keeps `on delete restrict` only as the backstop that forces the explicit path. |
Still open, technical only: the Storage layout `<sha256>.svg` is applied by
the importer step (4b) with a bucket policy that authorises through the
sheet, never through a hash alone.
## 6. Official equine sheet: import (Step 4b)
`packages/anatomy` holds a one-off, deterministic importer
(`pnpm import:equine`) that reads `Horse.svg`, `Horse_head.svg` and
`pathologies.json` and writes `supabase/seed/anatomical-sheets/equine/v1/`:
the canonical `document.json`, `legacy-id-map.json` (every legacy
`data-anno-id`, category slug and view key → new id), `assets.json` and the
byte-identical SVG copies, `IMPORT-REPORT.md` (French, for the osteopath:
volumes in / out, every mapping, every anomaly to validate) and
`equine_v1.sql`, the idempotent seed that creates the platform-owned sheet
`faunosteo-cheval` (private, official) with its two asset rows and draft v1.
Rules of the import:
- ids are explicit and stable: annotation id = catalog zone key when FR and
EN names match exactly (26 / 26), finding zone id = catalog key, views
`main` and `head`, trigger `head-trigger`; nothing matches by label at
runtime;
- no medical correction: catalog ids and labels are kept verbatim
(`ssb-dysfunctions` under `sphenoid` included) and every doubt is an entry
of the report; only technical slugs (degraded category ids) are
normalised, and the report says so;
- no publication: the seed inserts a draft through
`private.insert_sheet_draft` (audited with a null actor) and never calls
`publish_sheet_version`; only a platform admin can publish it, after the
business review of the report (pgTAP 007 pins both);
- the source files under `apps/app/public/species/equine/` stay untouched
and keep serving the current application.
Storage: bucket `anatomical-sheet-assets` (private, SVG only, 20 MiB cap),
objects `<sha256>.svg`, read policy `anatomical_sheet_assets_read` through
`private.can_read_sheet_asset_object` (published reference of a usable
sheet, or editor); no API writes (operator upload, `SUPABASE.md` §3.1).
+5
View File
@@ -144,6 +144,11 @@ Risks: subtle divergences between parser and importer on the detail trigger (no
official equine sheet as a DRAFT with an import report, published only after business review.
packages/anatomy is created at Step 4b. Labels use `{ fr, en }` objects, annotation→findings is
`finding_zone_id`, finding categories carry a `kind`; see the spec for the final field names.
Step 4b done 2026-10-09: packages/anatomy importer + `pnpm import:equine`, seed
supabase/seed/anatomical-sheets/equine/v1 (draft, not published), Storage bucket + policy
(migration 20261009100000), pgTAP 006/007. Business decisions of 2026-10-09 recorded in
ANATOMICAL_SHEET_MODEL.md §5 (follow-gated use → community step; verified publication →
identity step; erasure path → retention step).
```
```text
+36 -5
View File
@@ -14,8 +14,12 @@ supabase/
│ ├─ 20261008100100_profiles.sql profiles + auth.users trigger + RLS
│ ├─ 20261008100200_platform_roles.sql platform_role, profile_roles, helpers, RPCs
│ ├─ 20261008110000_anatomical_sheets.sql species, sheets, immutable versions, assets, lifecycle RPCs
│ └─ 20261008110100_private_execute_hardening.sql EXECUTE revoked from PUBLIC on the Step 3 helpers
│ ├─ 20261008110100_private_execute_hardening.sql EXECUTE revoked from PUBLIC on the Step 3 helpers
│ └─ 20261009100000_sheet_asset_storage.sql bucket anatomical-sheet-assets + read policy through the sheet
├─ seed.sql LOCAL dev accounts + first owner (never run in prod)
├─ seed/anatomical-sheets/equine/v1/ official equine sheet as a DRAFT, generated by `pnpm import:equine`
│ ├─ equine_v1.sql idempotent seed (sheet, 2 asset rows, draft v1), applied by db reset and by PGlite
│ └─ document.json, legacy-id-map.json, assets.json, assets/*.svg, IMPORT-REPORT.md
└─ tests/ pgTAP, one file per concern, allowed AND denied paths
packages/supabase/
├─ src/client.ts createBrowserClient() (anon key, PKCE)
@@ -62,6 +66,33 @@ Local endpoints (`config.toml`):
`pnpm db:start` prints the `anon` and `service_role` keys. Only the anon key
ever reaches the browser.
Two kinds of seed (`config.toml [db.seed] sql_paths`):
| File | Scope | Content |
| --------------- | ----------------- | ---------------------------------------------------------------------------------- |
| `seed.sql` | local only | dev accounts + first owner |
| `seed/**/*.sql` | every environment | versioned reference data, idempotent (today: the official equine sheet as a draft) |
The PGlite harness applies `seed/**` after the migrations, `seed.sql` never
(it needs the real auth schema). On another environment, apply a versioned
seed with `psql -f` from a privileged session, then upload its assets (§3.1).
### 3.1 Sheet assets (Storage)
SVG files live in the private bucket `anatomical-sheet-assets`, keyed by
content (`<sha256>.svg`). Reading goes through the sheet (policy
`anatomical_sheet_assets_read`): a published version of a usable sheet, or
any version for its editors. No API role uploads; the operator does, with
the service key, from the generated seed folder:
```bash
SUPABASE_URL=http://127.0.0.1:54321 SUPABASE_SERVICE_ROLE_KEY=<service key> \
pnpm assets:upload supabase/seed/anatomical-sheets/equine/v1
```
The script verifies each file against `assets.json` (sha256, size) before
uploading and skips objects already present.
Seed accounts (local only, password `LocalDev-only-password-1`):
| Email | Role |
@@ -93,10 +124,10 @@ RLS enabled, no `using (true)` / `with check (true)` policy for `anon` or
Two runners, one SQL source of truth (`supabase/tests/*.sql`, pgTAP):
| Command | Engine | Needs Docker | What runs |
| -------------------------------------------- | ------------------------------------------------ | ------------ | ------------------------------------------------------------------------------------------------------------------------ |
| `pnpm --filter @faunosteo/supabase test:run` | PGlite (PostgreSQL 17 in WASM) | no | shim of the Supabase base schema + all migrations + every pgTAP file; schema ↔ types check; client factory; publish gate |
| `pnpm db:test` | `supabase test db` (pg_prove in the local stack) | yes | the same pgTAP files against the real Supabase image |
| Command | Engine | Needs Docker | What runs |
| -------------------------------------------- | ------------------------------------------------ | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `pnpm --filter @faunosteo/supabase test:run` | PGlite (PostgreSQL 17 in WASM) | no | shim of the Supabase base schema (auth + storage tables) + all migrations + `seed/**` + every pgTAP file; schema ↔ types check; client factory; publish gate |
| `pnpm db:test` | `supabase test db` (pg_prove in the local stack) | yes | the same pgTAP files against the real Supabase image |
`pnpm test:run` at the root runs the PGlite suite together with the app
suite. The shim (`packages/supabase/tests/db/supabase-shim.sql`) recreates