docs(docs): V1-1 owner decisions N1-N9 and M1 as built

Contract: N4 voiding instead of deletion, N5 date constraints, N6 write budget per workspace under a lock, N7 effective-privilege wording and residual admin paths, N9 audit metadata limited to ids; M1 as-built notes and isolated-stack results (§8.1). SUPABASE.md §3.3 with the owner procedure to apply M1 on DEV without reset; backend architecture, test strategy, plan and CLAUDE.md lines.
This commit is contained in:
bchanot committed 2026-10-25 20:00:06 +01:00
1 parent 7bf4fb6079
commit 0f8c9833cc
6 files changed
+237 -59

No files matched your search

+36 -2
View File
@@ -18,7 +18,8 @@ supabase/
│ ├─ 20261009100000_sheet_asset_storage.sql bucket anatomical-sheet-assets + read policy through the sheet
│ ├─ 20261010100000_sheet_document_schema_v2.sql document schema 2: references, review_status, count_range checks
│ ├─ 20261011100000_profiles_professional.sql practice_name, professional_title, siret
│ └─ 20261013100000_files_foundation.sql assets table, seven private buckets, avatar policies through assets, purge queue, browser + worker RPCs (STORAGE.md)
│ ├─ 20261013100000_files_foundation.sql assets table, seven private buckets, avatar policies through assets, purge queue, browser + worker RPCs (STORAGE.md)
│ └─ 20261025100000_workspaces.sql V1-1.1 (M1): workspaces, workspace_members, personal workspace per account, access helpers, audit correlation cap (§3.3)
├─ seed.sql LOCAL dev accounts + first owner (never run in prod)
├─ seed/anatomical-sheets/equine/ official equine sheet as a DRAFT, generated by `pnpm import:equine`
│ ├─ legacy-sources/ the historical Horse.svg, Horse_head.svg, pathologies.json, vertebrae.ts (importer input)
@@ -181,11 +182,44 @@ Seed accounts (local only, password `LocalDev-only-password-1`):
| `alice@faunosteo.local` | plain user |
| `bob@faunosteo.local` | plain user |
### 3.3 Workspaces (V1-1.1, migration M1)
Contract: `docs/development/V1-1_OWNERS_ANIMALS.md` §4, §8.1, §9. Every
account has exactly one personal workspace, created by the trigger
`profiles_create_personal_workspace` in the sign-up transaction (GoTrue →
`handle_new_auth_user` → profile → workspace + `holder` membership), through
the single write path `private.ensure_personal_workspace(uuid)` (one
statement, idempotent, race-safe). A deferred constraint trigger refuses at
commit a personal workspace without its holder or with any other member.
Reads: RLS through `private.caller_workspace_ids()` (member, active profile,
confirmed email, `auth.uid()` only). No API role writes either table; `anon`
and `service_role` hold no privilege on them. From M2 on, record tables use
the same helpers; the app passes its workspace id explicitly.
M1 is written and tested on PGlite and on an isolated stack, not applied to
the DEV stack. Applying it there is an owner action, without a reset:
```bash
pnpm supabase db dump --local -f ~/faunosteo-dev-schema-before-m1.sql # optional safety copy: schema
pnpm supabase db dump --local --data-only -f ~/faunosteo-dev-data-before-m1.sql # and data (DEV accounts are fictitious)
pnpm supabase migration list --local # 20261025100000 listed as local only
pnpm supabase migration up --local # applies the pending migration; its backfill creates the missing workspaces
pnpm db:test # the 12 pgTAP files on the DEV database (each rolled back)
pnpm db:types:check # no diff with the committed types
```
Afterwards every existing account has its workspace: in Studio's SQL editor,
`select count(*) from public.profiles p where not exists (select 1 from
public.workspaces w where w.personal_user_id = p.id)` returns 0. The migration is forward-only: undoing it means restoring
the dumps or writing a new migration. `pnpm db:reset` also applies it, but
replays the whole database from zero and loses the DEV accounts and data.
## 4. Writing a migration
1. `pnpm supabase migration new <name>` creates `supabase/migrations/<timestamp>_<name>.sql`.
2. A migration that adds a table adds, in the same file: RLS enable, explicit
`revoke all ... from public, anon, authenticated` then the exact grants,
`revoke all ... from public, anon, authenticated` (and `service_role` for
V1-1 record tables, contract N7) then the exact grants,
separate SELECT / INSERT / UPDATE / DELETE policies, indexes, comments.
3. Add or extend a pgTAP file under `supabase/tests/`: the allowed path and
every denied path (other user, anon, direct write bypassing an RPC). Scope