feat(identity): content unit data hygiene — specials, provisional promotion, duplicate merge (DH-1)

- metadata.includeSpecials (default true): full refresh and the language
  backfill fetch TMDB season 0 (specials) when present, like MP; season 0
  stays out of the episode-total ledger
- refreshMetadata promotes provisional season/episode units that match the
  TMDB season/episode layout to confirmed (source=tmdb), keeping ids and all
  references; non-matching units stay provisional
- content_unit.source (migration 0053): release / file / tmdb / user
- duplicate units (same entity/kind/season/episode/content type/segment) are
  merged as a refresh step and via `scripts/identity-cleanup.ts
  --merge-duplicates` (dry-run by default); keeper = most referenced, then
  confirmed, then earliest; references auto-discovered via FKs and repointed
- ensureUnits takes a per-unit advisory xact lock to stop concurrent lazy
  creation from producing duplicates
- runbooks updated; user DB read-only dry-run: 征途 S01E09/E10 4 units each
  -> 1 each (6 removed), not applied

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-09-29 20:49:56 +08:00
1 parent 2847512501
commit 044e718ec6
21 files changed
+734 -111

No files matched your search

@@ -136,7 +136,8 @@ describe.skipIf(!up)("订阅搜索关键词与集播出日期", () => {
expect(eps.filter((x) => x.season_number === 3)).toHaveLength(10);
expect(eps.filter((x) => x.season_number === 1)).toHaveLength(0);
const first = eps.find((x) => x.season_number === 2 && x.episode_number === 1)!;
expect(first).toMatchObject({ id: e1, status: "provisional", air: "2023-06-22" });
// 已有的临时集单元:id 不变,补日期,对上 TMDB 季集结构后转正式(DH-1)
expect(first).toMatchObject({ id: e1, status: "confirmed", air: "2023-06-22" });
expect(eps.find((x) => x.season_number === 2 && x.episode_number === 2)).toMatchObject({
status: "confirmed",
air: "2023-06-29",