fix(episode): 半转正的临时季也进季表;迁移 0091 补做 DH-1 前漏掉的季集转正
兰香缘等 26 部:季单元是资源懒建的临时单元,TMDB 集已挂在下面成了正式单元, 季单元没转正,季表丢掉整季,资源全成「元数据未覆盖」。 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
1 parent
8ff1817845
commit
4866e735c8
3 files changed
+87
-1
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import type { Kysely } from "kysely";
|
||||
import { execDdl } from "../src/migration-helpers.ts";
|
||||
|
||||
// DH-1 之前(2026-09-29 v0.3.0 前)刷新的剧集留下的半转正数据:季单元是资源懒建的临时单元,
|
||||
// TMDB 的集已挂在它下面成了正式单元,季单元本身和当时对上 TMDB 的临时集却没转正。
|
||||
// 季表只认正式季,于是整季消失、资源全成「元数据未覆盖」(兰香缘等 26 部)。
|
||||
// 这里补做当时漏掉的转正:下面有 TMDB 正式集的临时季 → 正式;这些季里集号在总集数以内、没有同号正式集的临时集 → 正式。
|
||||
// 超出总集数的临时集保持临时(对不上 TMDB)。只改状态与来源,不删行;down 不回退。
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: 迁移不依赖应用表类型
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await execDdl(
|
||||
db,
|
||||
`
|
||||
create temp table _covered_season on commit drop as
|
||||
select s.id, s.episode_total from content_unit s
|
||||
where s.kind = 'season' and s.status = 'provisional'
|
||||
and exists (select 1 from content_unit c
|
||||
where c.parent_unit_id = s.id and c.kind = 'episode'
|
||||
and c.status = 'confirmed' and c.source = 'tmdb');
|
||||
|
||||
update content_unit c set status = 'confirmed', source = 'tmdb'
|
||||
from _covered_season s
|
||||
where c.parent_unit_id = s.id and c.kind = 'episode' and c.status = 'provisional'
|
||||
and c.episode_number between 1 and coalesce(s.episode_total, 0)
|
||||
and not exists (select 1 from content_unit d
|
||||
where d.parent_unit_id = s.id and d.kind = 'episode'
|
||||
and d.status = 'confirmed' and d.episode_number = c.episode_number);
|
||||
|
||||
update content_unit u set status = 'confirmed', source = 'tmdb'
|
||||
from _covered_season s where u.id = s.id;
|
||||
`,
|
||||
);
|
||||
}
|
||||
|
||||
// biome-ignore lint/suspicious/noExplicitAny: 迁移不依赖应用表类型
|
||||
export async function down(_db: Kysely<any>): Promise<void> {}
|
||||
Reference in new issue
Block a user