-- 每次搜索新增记录；每条搜索结果新增独立候选并关联 search_id。
-- 执行前请确认当前表仍存在以下两个旧唯一索引。

ALTER TABLE `video_discovery_search`
  DROP INDEX `uk_video_discovery_search_key`;

ALTER TABLE `video_discovery_candidate`
  DROP INDEX `uk_video_discovery_candidate_run_aweme`,
  ADD COLUMN `search_id` BIGINT NULL
    COMMENT '直接关联 video_discovery_search.id；历史数据允许为空'
    AFTER `run_id`,
  ADD INDEX `idx_video_discovery_candidate_search` (`search_id`, `id`),
  ADD CONSTRAINT `fk_video_discovery_candidate_search`
    FOREIGN KEY (`search_id`) REFERENCES `video_discovery_search` (`id`)
    ON DELETE RESTRICT;
