Fase 3b: de Hero bewaart zijn foto's in de bibliotheektabel (schakelaar uit), HeroImages blijft een kopie, controle bij het opstarten, FK-migratie met Down

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 00:10:58 +01:00
co-authored by Claude Sonnet 5.5
parent 53e1e3c8a6
commit 7246efccc1
18 changed files with 957 additions and 11 deletions
@@ -1,6 +1,6 @@
# Phase 3: the library becomes the truth, the old Hero tables and the switches go
Status: plan only (2026-11-17). **Nothing in this plan is built or run.** Rules from Bryan, relayed by SLS-Main: build it only after phase 2 is verified on test; dropping the old tables only on TEST, with a back-up and rollback plan and a notice to SLS-Main first; never on production without a separate go from Bryan; no PR for the phase-2/3 branch before #22 is merged.
Status (2026-11-18): steps 3a and 3b are BUILT on `feature/media-library-phase2` (3b behind a switch that is off by default); step 3c (dropping the old table and the switches) is NOT built and NOT run. Rules from Bryan, relayed by SLS-Main: build it only after phase 2 is verified on test; dropping the old tables only on TEST, with a back-up and rollback plan and a notice to SLS-Main first; never on production without a separate go from Bryan; no PR for the phase-2/3 branch before #22 is merged.
## Where phase 2 leaves us
@@ -41,3 +41,22 @@ Public addresses (`/media/hero/<setHash>/...`), ids and hashes stay as they are
- 3c is a separate release after a quiet period on test (assumption: at least a week), not part of the first rollout of phase 2.
- The clean-up job of the Hero (`HeroMediaCleanup`) moves to the library in 3b, so other modules can use the same retention rules.
## As built: 3a and 3b (2026-11-18)
**3a, expand (Media migration `AddHeroPhotoColumns`, additive):** `MediaAssets` gets `SetHash`, `Variants` (the hero's own JSON), `WideFocusX/Y/Zoom`, `TallFocusX/Y/Zoom`; `MediaUses` gets `Variants`. The verified copy, the write-through and the read check fill and compare them (a difference in the set or variants shows in the library check).
**3b, the switch (Hero migration `DropSlideImageForeignKey` + switch `Media__Library__HeroPhotosInLibrary`, default off):**
- The migration drops only the foreign key `FK_HeroSlides_HeroImages_ImageId` (a slide may point at a photo that is only in `MediaAssets`). It has a `Down` that puts it back. The model snapshot is deliberately unchanged. The service layer already checks that a photo exists and is not removed while a slide uses it.
- With the switch **on**, the Hero's photo entity is mapped to the library table: rows of `MediaAssets` with module `hero` (columns `DefaultFocusX/Y/Zoom`, a `Module` column set to `hero`, a query filter on it). Everything else in the hero (services, renderer, public mapping, clean-up) is unchanged and runs on those rows. The library owns that table and its migrations; the hero's context excludes it from its own.
- `HeroImages` stays a **complete copy** while the switch is on (`HeroLegacyImageMirror` after every saved change), so switching back loses nothing.
- **Start-up guard:** with the switch on, the application refuses to start (clear message in the log) unless the library holds every photo of `HeroImages` with the same hash, set and variants. So the order is fixed: copy first, library check, then the switch.
- Public addresses, ids and hashes are unchanged; the golden files are untouched.
**Order on test (each step a deploy, SLS-Main tells Bryan):**
1. Deploy with `media_library_copy=on` (and `media_library_dual_write=on`): the migrations run and the copy fills the new columns for the existing photos. Open "Controle bibliotheek": it must say that the library matches the hero (it now also compares set and variants).
2. Deploy with `media_library_hero_photos=on`. If the guard refuses to start, the log says why; set the switch back to off.
3. Check the hero admin (upload, crop a slide, save, trash and restore) and the public site; the library check still matches.
4. Rollback at any time: `media_library_hero_photos=off` (the application reads `HeroImages` again, a complete copy). To undo the foreign-key migration too: the `Down` of `DropSlideImageForeignKey`. Last resort: the restore point of the test sites.
**Step 3c (not built):** drop `HeroImages` and the legacy mirror, remove the three media switches and the copier, make the library table the only home. Needs: Bryan's verification of 3b on test, a notice to SLS-Main with the exact migration, a fresh restore point; test only.