Skip to content

feat(seeds): re-enable lecture writes against the new Lectures + LectureClips shape - #313

Merged
Ardnived merged 1 commit into
mainfrom
fix/seed-lectures-clip-aware
Apr 26, 2026
Merged

Ardnived merged 1 commit into
mainfrom
fix/seed-lectures-clip-aware

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

Closes #311.

Drops the throw-on-use guards introduced in PR #292 and rewires the wemeditate + storyblok importers to upsert a parent Lecture (keyed on nirmalVidyaVimeoUrl) plus a single full-video child LectureClip per unique vimeo_id. Rich-text content references the clip, not the parent — matching the post-#291 polymorphic move (AppCards, ShowcaseBlock, RelationshipFeature, ContentIndexBlock, wm-app-config.postRealizationLecture) everywhere else.

What changed

  • convertVimeo (seeds/lib/lexicalConverter.ts) — handles the actual nested data.items[0].vimeo_id shape from wemeditate source data (the original code looked at data.vimeo_id which was always undefined for this dataset, so the legacy code never actually wrote any vimeo references). Emits lecture-clips relationships. Drops YouTube blocks with a logged warning — there is no Nirmala Vidya YouTube ingest path. ConversionContext.lectureMap renamed to lectureClipMap (now vimeo_id → clipId).

  • WeMeditateImporter.importLectures (seeds/wemeditate/import.ts) — walks all page-content blocks, dedupes vimeo_ids (40 unique across 161 occurrences in data.json), upserts parent Lecture + child Clip per id. Per-vimeo error isolation: a single NV API failure (404, transient blip, missing duration) is contained — the failing id is just absent from lectureClipMap and the converter logs a missing-clip warning. Preloads both lectures (with metadata + title so skip-mode reads see the NV-fetched duration without a follow-up fetch) and lecture-clips.

  • StoryblokImporter.upsertLecture (seeds/storyblok/import.ts) — mirrors the same parent + clip pattern. Returns the child clip id (not the lecture id) and the call site emits a lecture-clips relationship node. Storyblok currently has 0 video stories in source, so this code path is unexercised but compiles and degrades safely.

  • Lectures.nirmalVidyaVimeoUrl (src/collections/resources/Lectures.ts) — promoted the natural key from convention to schema with unique: true, index: true. New migration 20260426_105204 adds the unique index.

    Pre-merge action item for the reviewer/operator: before deploying, run SELECT nirmal_vidya_vimeo_url, COUNT(*) FROM lectures GROUP BY 1 HAVING COUNT(*) > 1; against staging/prod. Per feat(lectures): split Lectures into Lectures + LectureClips #292 the lectures table was dropped during the split, so duplicates are unlikely — but the migration will fail loudly if any exist.

  • Test infrastructure — testData.createLecture now generates a unique numeric vimeo id per call so multiple lectures created within one test file don't collide with the new unique constraint. The wemeditate / storyblok metadata files (expectedCounts.ts, setup-test-db.ts, check-db-stats.ts) now include lectures (40) + lecture-clips (40) for wemeditate.

Tests added

File Lane Cases
tests/unit/convert-vimeo.spec.ts unit (no Payload bootstrap) 5
tests/int/seeds-lectures.int.spec.ts int (mocks @/lib/nirmalaVidyaApi per existing convention) 3

The integration spec covers: parent + clip upsert with endTime === metadata.duration, skip-mode no-op on re-run (NV hook does not re-fire), and per-vimeo error isolation when a single NV call rejects.

Out of scope

  • Backfilling NV metadata for production lectures created before this PR (handled by the monthly SyncLectureMetadata job)
  • Multi-clip-per-lecture seed authoring (no source data carries clip boundaries)
  • A YouTube-as-lecture path (would need a new youtubeUrl field + a YouTube metadata fetcher; track separately if editorial requires it)

Test Results

  • Integration tests: 583 passed, 0 failed, 0 skipped
  • Unit tests: 226 passed, 0 failed, 0 skipped
  • Lint: clean
  • Typecheck (pnpm tsc --noEmit): clean
  • Build (pnpm build): ✓ Success

Test plan

  • Reviewer runs the duplicate-URL check above against staging/prod before merge
  • After merge, operator runs pnpm seed wemeditate (with NIRMALA_VIDYA_API_KEY set) and confirms ~40 new Lectures + ~40 LectureClips, each clip's endTime matching its parent's metadata.duration
  • Re-run pnpm seed wemeditate is a flat-counts no-op
  • Spot-check: open a wemeditate page known to embed a Vimeo block in admin and confirm the rich-text contains a relationship node with relationTo: 'lecture-clips'

🤖 Generated with Claude Code

…ureClips shape

Drops the throw-on-use guards introduced in #292 and rewires the wemeditate +
storyblok importers to upsert a parent Lecture (keyed on `nirmalVidyaVimeoUrl`)
plus a single full-video child LectureClip per unique vimeo_id. Rich-text
content references the clip, not the parent, matching the post-#291 polymorphic
move everywhere else.

- `convertVimeo`: handles the actual nested `data.items[0].vimeo_id` shape from
  wemeditate source data; emits `lecture-clips` relationships; drops YouTube
  blocks with a logged warning (no NV YouTube ingest path)
- `WeMeditateImporter.importLectures`: per-vimeo error isolation so a single NV
  API failure doesn't kill the 40-video batch — the failed id is just absent
  from `lectureClipMap` and the converter logs a missing-clip warning
- `StoryblokImporter.upsertLecture`: same parent+clip pattern; returns the
  child clip id and the call site emits a `lecture-clips` relationship node
- `Lectures.nirmalVidyaVimeoUrl`: promote the natural key from convention to
  schema with `unique: true, index: true` (new migration `20260426_105204`)

Includes a unit-lane `convert-vimeo.spec.ts` for the pure converter and an
integration `seeds-lectures.int.spec.ts` that mocks the NV API to verify the
end-to-end parent+clip flow, skip-mode no-op, and per-vimeo error isolation.

Closes #311

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Ardnived
Ardnived merged commit 9466d0a into main Apr 26, 2026
@Ardnived
Ardnived deleted the fix/seed-lectures-clip-aware branch April 26, 2026 13:33
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.

Re-enable seed writes against the new Lectures + LectureClips shape (#291 follow-up)

1 participant