Files
faunosteo/docs/development/V1-2-6_R3_SQL_CHECKPOINT.md
T

4.5 KiB

R3 SQL checkpoint: a true last-modification date for the sheet list

Status: DESIGN ACCEPTED by the owner, 2026-11-09 (verdict « R0 — Verdict de revue graphique propriétaire », BDR-109), after the brief « R0 — Décisions propriétaire et dernière validation graphique » (A7). No migration is created or applied for now; writing and applying it needs the owner's later go. R3 keeps its split before and after this checkpoint (section 5). Companion of V1-2-6_U1_CORRECTIONS.md (lot R3).

1. The problem

The admin list and the sheet page read private.official_sheet_admin_summary (supabase/migrations/ 20261102100000_sheet_admin_reads.sql:40-92), which returns anatomical_sheets.updated_at (:54). A draft save writes anatomical_sheet_versions only (public.save_sheet_draft, 20261028110000_sheet_review_workflow.sql:569-630), so the sheet row's date does not move when a draft is edited. Read on the sandbox (2026-11-09, select only): 28 of 219 official sheets have a version newer than the sheet row, up to 15 s apart; the fixed historical draft and the owner's cheval11 happen to agree. The owner's rule until this lands: no creation date shown as a modification date, no misleading sort.

2. Proposed change (one read change, no table, policy or privilege change)

A new migration replaces private.official_sheet_admin_summary with the same body plus one key:

'last_modified_at', greatest(s.updated_at, (
  select max(v.updated_at) from public.anatomical_sheet_versions v where v.sheet_id = s.id))
  • greatest ignores a null, so a sheet without a version keeps its own date.
  • Both columns are kept by the existing set_updated_at triggers (20261008110000_anatomical_sheets.sql:90-92, :143-145): a draft save, a status change, a publication, an archive, a metadata edit and the working copy's own writes all move one of them. Review rounds and audit rows are not modifications of the sheet and do not count.
  • The per-sheet max uses the existing unique index on (sheet_id, version_number) (:118) for the lookup by sheet_id; the list is already one summary call per sheet, so the cost is one more indexed aggregate per row. RR-13 (server paging) will sort on the same expression.
  • get_official_sheet_admin and list_official_sheets_admin both call the summary and return the key unchanged; their signatures, security definer, search_path and grants are untouched (the revokes at 20261102100000_sheet_admin_reads.sql:244 stay in force).
  • updated_at stays in the payload with its current meaning; nothing that reads it changes.

3. Verification the checkpoint asks for

  • pgTAP in supabase/tests/022_sheet_admin_reads.sql: a draft save moves last_modified_at and not updated_at; a sheet metadata change moves both; a sheet without a version answers its own date; the key is present for every listed sheet; the call rights unchanged (existing tests :186-190 re-run).
  • pnpm --filter @faunosteo/supabase test:run (PGlite) and pnpm db:test on a real stack.
  • pnpm db:types: the functions return jsonb, so the generated types do not change; the hand-written summary type in packages/supabase/src/sheets.ts gains last_modified_at.

4. Applying it to a stack: an owner decision

scripts/db-sandbox.sh has no command that applies a new migration to a running sandbox: up upgrade builds a new one, which removes the current sandbox (owner rule: inventory, then a go for that operation). Three paths, none taken without the owner:

Path Effect
a. Apply to the trial stack once it exists (pnpm db:trial migrate, TRIAL_STACK.md §3.4) No sandbox change; the owner sees the date in the trial
b. A migrate command added to db-sandbox.sh (forward only, no reset) A script change, its own go; keeps the sandbox's data
c. pnpm db:sandbox up upgrade 2026… on a new sandbox Removes the current sandbox: inventory and owner go first

Recommendation: a (with b only if the shell suite must see the date before the trial stack exists). PGlite and pnpm db:test need no existing stack.

5. What R3 does before and after

  • Before: search and clear, sort by name only, no date on the rows, the Administration card without a date or a « most recent » claim (the first five by name, with « Voir les N fiches »).
  • After: « Modifiée le … » from last_modified_at, « Dernière modification » as the default sort, the card listing the five most recently modified sheets. Boards 28 and 29 draw this final state.