import type { Kysely } from "kysely"; import { execDdl } from "../src/migration-helpers.ts"; // W4-A 候选评估记录去重:同一 (acquisition_slot, source_release) 只保留最新一条(artifact title=candidate_evaluation)。 // 先清掉历史重复(保留 updated_at 最新的一条),再加唯一表达式索引,写入端按该键 upsert。 // biome-ignore lint/suspicious/noExplicitAny: 迁移不依赖应用表类型 export async function up(db: Kysely): Promise { await execDdl( db, ` delete from artifact a using artifact b where a.title = 'candidate_evaluation' and b.title = 'candidate_evaluation' and a.subject_type = 'acquisition_slot' and b.subject_type = 'acquisition_slot' and a.subject_id = b.subject_id and (a.content->>'sourceReleaseId') = (b.content->>'sourceReleaseId') and (a.updated_at, a.id) < (b.updated_at, b.id); create unique index artifact_candidate_slot_release on artifact (subject_id, (content->>'sourceReleaseId')) where title = 'candidate_evaluation' and subject_type = 'acquisition_slot'; `, ); } // biome-ignore lint/suspicious/noExplicitAny: 同上 export async function down(db: Kysely): Promise { await execDdl(db, "drop index if exists artifact_candidate_slot_release;"); }