Files
UHD_Media_Tool/packages/db/migrations/0065_subtitle_sites.ts
T

32 lines
1.5 KiB
TypeScript

import type { Kysely } from "kysely";
import { execDdl, oneOf } from "../src/migration-helpers.ts";
// 字幕站(docs/plan/subtitles.md 第 2 步):站点类型 subtitle、适配器 subtitle(SubHD、字幕库),
// 复用站点的代理 / 限流 / 健康 / 浏览器会话;不参与资源搜索、快照、RSS。
const KINDS = ["pt", "public_bt", "rss_feed", "torznab", "subtitle"];
const ADAPTERS = ["nexusphp", "mteam_api", "api", "generic_rss", "subtitle"];
const OLD_KINDS = ["pt", "public_bt", "rss_feed", "torznab"];
const OLD_ADAPTERS = ["nexusphp", "mteam_api", "api", "generic_rss"];
// biome-ignore lint/suspicious/noExplicitAny: 迁移不依赖应用表类型
export async function up(db: Kysely<any>): Promise<void> {
await execDdl(
db,
`alter table site drop constraint if exists site_kind_check;
alter table site add constraint site_kind_check ${oneOf("kind", KINDS)};
alter table site drop constraint if exists site_adapter_check;
alter table site add constraint site_adapter_check ${oneOf("adapter", ADAPTERS)};`,
);
}
// biome-ignore lint/suspicious/noExplicitAny: 同上
export async function down(db: Kysely<any>): Promise<void> {
await execDdl(
db,
`delete from site where kind = 'subtitle';
alter table site drop constraint if exists site_kind_check;
alter table site add constraint site_kind_check ${oneOf("kind", OLD_KINDS)};
alter table site drop constraint if exists site_adapter_check;
alter table site add constraint site_adapter_check ${oneOf("adapter", OLD_ADAPTERS)};`,
);
}