import type { Kysely } from "kysely"; import { execDdl, oneOf } from "../src/migration-helpers.ts"; // 下载侧可见性:decision.kind 增加 // - downloader_offline:下载器连续不可达超过一段时间(按实例去重,恢复后自动关闭) // - cache_volume_unknown:下载目录读不到容量(路径映射 / 挂载问题,按卷去重,恢复后自动关闭) const OLD_DECISION_KINDS = [ "identity_ambiguous", "download_stalled", "download_failed", "path_conflict", "space_insufficient", "approval_required", "metadata_conflict", "source_unreachable", "other", "identity_unresolved", "episode_mapping", ]; const NEW_DECISION_KINDS = [...OLD_DECISION_KINDS, "downloader_offline", "cache_volume_unknown"]; const swapDecisionKinds = (values: readonly string[]) => ` alter table decision drop constraint decision_kind_check; alter table decision add constraint decision_kind_check ${oneOf("kind", values)}; `; // biome-ignore lint/suspicious/noExplicitAny: 迁移不依赖应用表类型 export async function up(db: Kysely): Promise { await execDdl(db, swapDecisionKinds(NEW_DECISION_KINDS)); } // biome-ignore lint/suspicious/noExplicitAny: 同上 export async function down(db: Kysely): Promise { await execDdl( db, `update decision set kind = 'other' where kind in ('downloader_offline', 'cache_volume_unknown'); ${swapDecisionKinds(OLD_DECISION_KINDS)}`, ); }