import type { Kysely } from "kysely"; import { dropTables, entityTable, execDdl, oneOf } from "../src/migration-helpers.ts"; // 运维域:reconcile_run(五类校验器的可恢复运行记录)、server_mapping(Emby 兼容库存映射,REQ §7.4、§8.1) // 外部库存"未知 ≠ 缺失";server_mapping 只是辅助证据,不构成文件纳管授权。 // biome-ignore lint/suspicious/noExplicitAny: 迁移不依赖应用表类型 export async function up(db: Kysely): Promise { await execDdl( db, ` ${entityTable( "reconcile_run", ` kind text not null ${oneOf("kind", ["identity", "metadata", "asset", "acquisition", "server"])}, mode text not null default 'normal' ${oneOf("mode", ["normal", "read_only"])}, status text not null default 'queued' ${oneOf("status", ["queued", "running", "succeeded", "partial", "failed", "cancelled"])}, scope jsonb not null default '{}'::jsonb, resume_cursor jsonb not null default '{}'::jsonb, stats jsonb not null default '{}'::jsonb, task_id uuid references task (id) on delete set null, error jsonb, started_at timestamptz, finished_at timestamptz`, )} create index reconcile_run_kind_idx on reconcile_run (kind, created_at desc); ${entityTable( "server_mapping", ` media_server_instance_id uuid not null references media_server_instance (id) on delete cascade, server_item_id text not null, item_type text not null ${oneOf("item_type", ["movie", "series", "season", "episode", "other"])}, media_entity_id uuid references media_entity (id) on delete set null, content_unit_id uuid references content_unit (id) on delete set null, media_asset_id uuid references media_asset (id) on delete set null, server_path text, path_mapping_id uuid references path_mapping (id) on delete set null, match_status text not null default 'unmatched' ${oneOf("match_status", ["matched", "ambiguous", "unmatched", "stale"])}, version_info jsonb not null default '{}'::jsonb, evidence jsonb not null default '{}'::jsonb, observed_at timestamptz not null default now(), constraint server_mapping_item_key unique (media_server_instance_id, server_item_id)`, )} create index server_mapping_entity_idx on server_mapping (media_entity_id) where media_entity_id is not null; `, ); } // biome-ignore lint/suspicious/noExplicitAny: 同上 export async function down(db: Kysely): Promise { await execDdl(db, dropTables(["server_mapping", "reconcile_run"])); }