Skip to content

feat(lectures): split Lectures into Lectures + LectureClips - #292

Merged
Ardnived merged 3 commits into
mainfrom
291-split-lectures-and-lecture-clips
Apr 21, 2026
Merged

Ardnived merged 3 commits into
mainfrom
291-split-lectures-and-lecture-clips

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Closes #291.

Summary

  • Lectures now models a full Nirmala Vidya talk. The new LectureClips child collection (hidden from the sidebar; managed through Lectures.clips with admin.allowCreate: true) holds per-excerpt metadata: parent, startTime/endTime, localized title, optional thumbnail, localized subtitlesUrl, tags.
  • Every external polymorphic reference that previously pointed at lectures is retargeted to lecture-clips: AppCards.content, ShowcaseBlock.items, RelationshipFeature.enabledCollections, wm-app-config.postRealizationLecture.
  • /api/lectures/for-viewer is rewritten to return a discriminated mixed feed of { type: 'lecture' | 'clip', ... }. Clips are eligible independently of their parent — the endpoint populates parent only when the parent is viewer-eligible, and merges parent thumbnail / subtitlesUrl into clips whose own values are empty (runs even when parent: null). All internal payload.find calls forward req so usage-tracking and rate-limit hooks attribute to the caller.
  • Lectures loses versions.drafts, startTime/endTime, and _status from defaultColumns; keeps access: { update: () => false } on nirmalVidyaVimeoUrl. LectureTags gains a second lectureClips join alongside the existing lectures join.
  • ContentIndexBlock gains lecture-clips as a new type option with a lectureClipFilters field mirroring lectureFilters (both pull from lecture-tags).
  • Seed entry points that wrote legacy lectures rows (seeds/wemeditate/import.ts, seeds/storyblok/import.ts, seeds/lib/lexicalConverter.ts) now throw with a pointer to the clip-aware follow-up PR. Seed test collection lists + expected counts updated. scripts/create-sample-page.ts skips the lectures branch.
  • Migration 20260421_030949 creates lecture_clips + relationship tables, drops _lectures_v*, drops startTime/endTime columns, rewires polymorphic _rels to lecture_clips_id. Manual augmentations: DELETE FROM lectures; (aligns with issue's "no data migration" decision) and fixing Drizzle's app_cards_rels / _app_cards_v_rels rebuild which mistakenly SELECT lecture_clips_id FROM the old table where only lectures_id existed.

Breaking changes (coordinate with consumers before deploy)

  • /api/lectures/for-viewer response shape: discriminated mixed array, possibly-null parent on clips, server-merged thumbnail / subtitlesUrl on clips. wemeditate-app and wemeditate-web need updates.
  • Tracked-read count per for-viewer call: 2 → 2-3. Clients with daily rate-limit quotas calibrated to the old behavior may need recalibration.
  • wm-app-config.postRealizationLecture now references lecture-clips.
  • AppCards / ShowcaseBlock / RichText polymorphic references no longer accept lectures — existing content referencing lectures will render as dangling (frontend already handles null relations).
  • All existing lectures rows are dropped by the migration per the issue decision; editors re-create from scratch.

Test plan

  • pnpm lint → 0 errors
  • pnpm tsc --noEmit → 0 errors
  • pnpm build → success
  • pnpm test:int → 524 passing (up from 519: added 10 new lecture-clips tests, renamed 5 for-viewer tests, 1 new collections-smoke canary, -6 startTime/endTime tests moved off Lectures)
  • Manual admin smoke: create a Lecture → add 2 clips inline via the parent's clips join → confirm LectureClips is not in the sidebar, LectureTags list view shows both lectures and lectureClips counts, and /api/lectures/for-viewer?limit=10&pathProgress=5 returns a mixed discriminated array with at least one clip whose parent: null and at least one clip whose empty thumbnail/subtitlesUrl gets server-merged from parent.
  • Before merging: run pnpm payload migrate against a copy of production and confirm the migration applies cleanly.

Test Results

  • Integration tests: 524 passed, 0 skipped, 0 failed
  • E2E tests: not applicable for this change
  • Build: ✓ Success
  • Pre-existing failures fixed: none encountered

🤖 Generated with Claude Code

Ardnived and others added 3 commits April 21, 2026 15:56
Lectures now models a full Nirmala Vidya talk; the new LectureClips child
collection holds time-range excerpts. External polymorphic references that
used to target `lectures` now target `lecture-clips` (AppCards, ShowcaseBlock,
richText RelationshipFeature, wm-app-config.postRealizationLecture). The
`/api/lectures/for-viewer` endpoint now returns a discriminated mixed feed of
`{ type: 'lecture' | 'clip', ... }` with conditional parent population and
server-merged thumbnail/subtitlesUrl fallbacks on clips. Seed entry points
that write legacy `lectures` rows throw with a pointer to the follow-up PR.

BREAKING: response shape for `/api/lectures/for-viewer` changes, and all
existing `lectures` rows are dropped by the migration.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…review polish

- Add deleteChildren() beforeDelete-hook factory in src/hooks/cascadeDeletion.ts.
  PayloadCMS has no native onDelete: cascade on relationship fields
  (payloadcms/payload#11177, #1209); the default ON DELETE SET NULL orphans
  rows whose parent relationship is required: true.
- Wire cascade into Lectures -> LectureClips and Albums -> Songs (both are
  composition relationships where the child has no meaning without the parent).
- Cache eligibleLectures in /api/lectures/for-viewer so parents already
  fetched at depth:1 don't trigger a second find.
- LectureClips polish: DEFAULT_CLIP_LENGTH_SECONDS constant for the 600s
  default; reword thumbnail/subtitlesUrl descriptions to clarify the
  fallback is applied by the for-viewer endpoint, not by collection CRUD.
- Drop unused tagViewers10 test fixture.
- Documentation & settings updates carried over from parallel sessions
  (AGENTS.md migration guidance, code-style + tests rules, PermissionRequest
  notifier).

Tests: 529 passing (+5 cascade-delete tests across Lectures and Albums).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- Set `push: false` on sqliteD1Adapter in src/payload.config.ts. Push mode
  silently skipped SQLite ALTER TABLE rebuilds needed for polymorphic-FK
  renames (issue #292), leaving local dev out of sync with production
  migrations. Local dev now takes the same code path as prod: run
  `pnpm payload migrate` before first boot.
- AGENTS.md: document the new local-dev workflow and warn against
  flipping push back on.
- Lectures.clips join: hide during create via `admin.condition` so the
  row can only be added once the parent has an id — matches the pattern
  used by the other post-create fields on this collection.
- .claude/settings.json: trim PermissionRequest voice hook (user edit).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Ardnived
Ardnived merged commit e53bcc7 into main Apr 21, 2026
Ardnived added a commit that referenced this pull request Apr 26, 2026
…ureClips shape (#313)

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 added a commit that referenced this pull request May 26, 2026
* feat(lectures): split Lectures into Lectures + LectureClips (#291)

Lectures now models a full Nirmala Vidya talk; the new LectureClips child
collection holds time-range excerpts. External polymorphic references that
used to target `lectures` now target `lecture-clips` (AppCards, ShowcaseBlock,
richText RelationshipFeature, wm-app-config.postRealizationLecture). The
`/api/lectures/for-viewer` endpoint now returns a discriminated mixed feed of
`{ type: 'lecture' | 'clip', ... }` with conditional parent population and
server-merged thumbnail/subtitlesUrl fallbacks on clips. Seed entry points
that write legacy `lectures` rows throw with a pointer to the follow-up PR.

BREAKING: response shape for `/api/lectures/for-viewer` changes, and all
existing `lectures` rows are dropped by the migration.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* feat(lectures,albums): generalize parent-child cascade-delete + #292 review polish

- Add deleteChildren() beforeDelete-hook factory in src/hooks/cascadeDeletion.ts.
  PayloadCMS has no native onDelete: cascade on relationship fields
  (payloadcms/payload#11177, #1209); the default ON DELETE SET NULL orphans
  rows whose parent relationship is required: true.
- Wire cascade into Lectures -> LectureClips and Albums -> Songs (both are
  composition relationships where the child has no meaning without the parent).
- Cache eligibleLectures in /api/lectures/for-viewer so parents already
  fetched at depth:1 don't trigger a second find.
- LectureClips polish: DEFAULT_CLIP_LENGTH_SECONDS constant for the 600s
  default; reword thumbnail/subtitlesUrl descriptions to clarify the
  fallback is applied by the for-viewer endpoint, not by collection CRUD.
- Drop unused tagViewers10 test fixture.
- Documentation & settings updates carried over from parallel sessions
  (AGENTS.md migration guidance, code-style + tests rules, PermissionRequest
  notifier).

Tests: 529 passing (+5 cascade-delete tests across Lectures and Albums).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* fix(db): disable Drizzle push on local D1 to stop schema drift

- Set `push: false` on sqliteD1Adapter in src/payload.config.ts. Push mode
  silently skipped SQLite ALTER TABLE rebuilds needed for polymorphic-FK
  renames (issue #292), leaving local dev out of sync with production
  migrations. Local dev now takes the same code path as prod: run
  `pnpm payload migrate` before first boot.
- AGENTS.md: document the new local-dev workflow and warn against
  flipping push back on.
- Lectures.clips join: hide during create via `admin.condition` so the
  row can only be added once the parent has an id — matches the pattern
  used by the other post-create fields on this collection.
- .claude/settings.json: trim PermissionRequest voice hook (user edit).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* feat(api): require select + populate for client reads (#199)

Adds validateClientQueryParamsHook to the usage plugin, which rejects
API client read requests that omit `select`, or that use `depth > 1`
without `populate`. Managers and write operations are unaffected.

The hook lives alongside rateLimitHook in the usage plugin because it
shares the same client-only gating and exclusion set (SYSTEM_EXCLUSIONS
+ 'clients'). It runs before rate limiting so malformed requests don't
burn rate-limit slots.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(api): args-based validation + trusted-internal escape hatch

- Switch validateClientQueryParamsHook from URL parsing to args inspection
  (`args.select`, `args.populate`, `args.depth`). Payload's REST handler
  already parses URL query params into args before the hook fires, and this
  avoids false-positive rejections on SDK callers that pass args directly.

- Add SKIP_CLIENT_QUERY_VALIDATION_KEY context flag for trusted internal
  endpoint handlers (appCardsForViewer, lecturesForViewer) that forward
  client req to payload.find(...) and need to shape their own response
  without enumerating every field via select. Rate limiting and usage
  tracking still fire — only query-param validation is skipped.

- Update role-based-access tests to pass `select` on client-simulating
  reads (matches the new enforcement).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor(api): replace SKIP_CLIENT_QUERY_VALIDATION_KEY with asTrustedReq helper

The exported constant + manual req spread pattern in every endpoint was
overkill for what is an internal implementation detail. An asTrustedReq()
helper encapsulates the bypass mechanism; the key string is inlined in
the two adjacent places that read/write it. Also inlines the intermediate
depth variable in the validation hook.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Ardnived added a commit that referenced this pull request Nov 5, 2026
…review polish

- Add deleteChildren() beforeDelete-hook factory in src/hooks/cascadeDeletion.ts.
  PayloadCMS has no native onDelete: cascade on relationship fields
  (payloadcms/payload#11177, #1209); the default ON DELETE SET NULL orphans
  rows whose parent relationship is required: true.
- Wire cascade into Lectures -> LectureClips and Albums -> Songs (both are
  composition relationships where the child has no meaning without the parent).
- Cache eligibleLectures in /api/lectures/for-viewer so parents already
  fetched at depth:1 don't trigger a second find.
- LectureClips polish: DEFAULT_CLIP_LENGTH_SECONDS constant for the 600s
  default; reword thumbnail/subtitlesUrl descriptions to clarify the
  fallback is applied by the for-viewer endpoint, not by collection CRUD.
- Drop unused tagViewers10 test fixture.
- Documentation & settings updates carried over from parallel sessions
  (AGENTS.md migration guidance, code-style + tests rules, PermissionRequest
  notifier).

Tests: 529 passing (+5 cascade-delete tests across Lectures and Albums).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Ardnived added a commit that referenced this pull request Nov 5, 2026
- Set `push: false` on sqliteD1Adapter in src/payload.config.ts. Push mode
  silently skipped SQLite ALTER TABLE rebuilds needed for polymorphic-FK
  renames (issue #292), leaving local dev out of sync with production
  migrations. Local dev now takes the same code path as prod: run
  `pnpm payload migrate` before first boot.
- AGENTS.md: document the new local-dev workflow and warn against
  flipping push back on.
- Lectures.clips join: hide during create via `admin.condition` so the
  row can only be added once the parent has an id — matches the pattern
  used by the other post-create fields on this collection.
- .claude/settings.json: trim PermissionRequest voice hook (user edit).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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.

Split Lectures into Lectures + LectureClips

1 participant