import type { Kysely } from "kysely"; import { dropTables, entityTable, execDdl, oneOf } from "../src/migration-helpers.ts"; // W2-B 来源补充(REQ §4.5、§4.6、§7.5): // - site.adapter 增加 api(MP 专用 API spider:Haidan/HDDolby/RousiPro/…,见 adapters/sites/spiders); // - source_release.resolution_locked:人工确认的身份关联,自动识别不得改写; // - site_snapshot:每次列表快照/实时补查/补漏的覆盖范围与新鲜度(不把一次分页伪称全站快照)。 // biome-ignore lint/suspicious/noExplicitAny: 迁移不依赖应用表类型 export async function up(db: Kysely): Promise { await execDdl( db, ` alter table site drop constraint site_adapter_check; alter table site add constraint site_adapter_check ${oneOf("adapter", ["nexusphp", "mteam_api", "api", "generic_rss"])}; alter table source_release add column resolution_locked boolean not null default false; ${entityTable( "site_snapshot", ` site_id uuid not null references site (id) on delete cascade, kind text not null ${oneOf("kind", ["periodic", "backfill", "live_search", "manual"])}, query text, filters jsonb not null default '{}'::jsonb, pages jsonb not null default '[]'::jsonb, item_count integer not null default 0, new_count integer not null default 0, status text not null default 'running' ${oneOf("status", ["running", "ok", "partial", "failed"])}, error jsonb, definition_version text, started_at timestamptz not null default now(), finished_at timestamptz`, )} create index site_snapshot_site_idx on site_snapshot (site_id, started_at desc); `, ); } // biome-ignore lint/suspicious/noExplicitAny: 同上 export async function down(db: Kysely): Promise { await execDdl( db, ` ${dropTables(["site_snapshot"])} alter table source_release drop column if exists resolution_locked; alter table site drop constraint site_adapter_check; alter table site add constraint site_adapter_check ${oneOf("adapter", ["nexusphp", "mteam_api", "generic_rss"])}; `, ); }