4.4 KiB
R3 SQL checkpoint: a true last-modification date for the sheet list
Status: PROPOSAL for the owner's dedicated SQL checkpoint, 2026-11-09 (brief « R0 — Décisions propriétaire et
dernière validation graphique », A7). Nothing here is written as a migration; no SQL, application, script or sandbox
change before the owner authorises this checkpoint. 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))
greatestignores a null, so a sheet without a version keeps its own date.- Both columns are kept by the existing
set_updated_attriggers (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
maxuses the existing unique index on(sheet_id, version_number)(:118) for the lookup bysheet_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_adminandlist_official_sheets_adminboth call the summary and return the key unchanged; their signatures,security definer,search_pathand grants are untouched (the revokes at20261102100000_sheet_admin_reads.sql:244stay in force).updated_atstays 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 moveslast_modified_atand notupdated_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) andpnpm db:teston a real stack.pnpm db:types: the functions returnjsonb, so the generated types do not change; the hand-written summary type inpackages/supabase/src/sheets.tsgainslast_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.