Skip to content

FIX [SCMS] Make seedMarkerNote boot-idempotent + pointer-repair safe 🧬#16

Merged
AdaInTheLab merged 1 commit intomainfrom
fix/seed-marker
Jan 7, 2026
Merged

FIX [SCMS] Make seedMarkerNote boot-idempotent + pointer-repair safe 🧬#16
AdaInTheLab merged 1 commit intomainfrom
fix/seed-marker

Conversation

@AdaInTheLab
Copy link
Owner

Summary

This PR fixes a long-standing mismatch between how the API marker note was seeded and how the Lab Notes system actually identifies and serves notes.

The root cause was an identity mismatch:

  • lab_note_revisions.note_id is a foreign key to lab_notes.id
  • The marker note already existed in dev with id = api-marker:en
  • Tests and seed logic incorrectly assumed id = slug:locale (api-marker-note:en)
  • This caused FK failures, missing revision pointers, and persistent 404s in the public detail route

What changed

  • Seed logic now resolves the real note primary key
    • Looks up the marker note by (slug, locale)
    • Reuses the existing lab_notes.id if present
    • Only creates a new note if it does not already exist
  • Revisions are now always inserted using the resolved note PK
    • lab_note_revisions.note_id correctly references lab_notes.id
  • Revision pointers are repaired deterministically
    • current_revision_id and published_revision_id are always set to the latest revision
  • Marker note is guaranteed to be publicly readable
    • status = published
    • published_at ensured
    • content_html populated if missing
  • Lab Note detail tests now pass reliably
    • No 404s caused by identity, FK, or projection filters

Why this matters

This aligns the marker note with the system’s real identity model instead of an assumed one.
It makes seeding:

  • safe in :memory: test DBs
  • safe in existing dev/prod DBs
  • idempotent on every boot

It also prevents future regressions where a note “exists” but is invisible due to mismatched IDs or missing revision pointers.

Notes

  • The marker note intentionally uses a legacy ID format (api-marker:en)
  • Seed logic must never assume lab_notes.id === slug:locale
  • This PR codifies that rule instead of fighting it

Tests

  • Lab Note detail › GET /lab-notes/:slug returns a note with contentHtml now passes
  • No schema or migration changes required

co-authored-by: Lyric <lyric@thehumanpatternlab.com>
co-authored-by: Carmel <carmel@thehumanpatternlab.com>
@AdaInTheLab AdaInTheLab merged commit 893e667 into main Jan 7, 2026
1 check passed
@AdaInTheLab AdaInTheLab deleted the fix/seed-marker branch January 7, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant