-- ============================================================================ -- ai_session.case_id 人工回填脚本(可选,绝不自动执行) -- ============================================================================ -- -- 背景: -- 多案件工作区隔离上线前创建的会话 ai_session.case_id 为 NULL,属于「历史全局会话」。 -- 默认口径是保留为 legacy:不出现在任何案件列表,不参与案件级 Agent 工作区 / 长期记忆链路。 -- -- 使用前提: -- 仅当你能确认某批历史会话确实属于某个案件时,才人工执行本脚本。 -- 脚本不会自动运行,也不会被应用启动流程调用。 -- -- 执行步骤: -- 1. 先查询待回填会话,核对数量与标题: -- select id, session_title, user_id, last_active_time -- from ai_session -- where case_id is null -- order by last_active_time desc; -- -- 2. 将下面的 :target_case_id 替换为目标案件 ID 后执行: -- update ai_session -- set case_id = :target_case_id -- where case_id is null -- and user_id = :target_user_id; -- 建议同时限定用户,避免误伤他人数据 -- -- 3. 回填后校验: -- select case_id, user_id, count(*) -- from ai_session -- where case_id = :target_case_id -- group by case_id, user_id; -- -- 注意: -- - 回填不会迁移旧的 data/agent-workspace 记忆文件;历史记忆仍保留在旧目录,不会被案件级链路读取。 -- - 回填前建议先备份 ai_session 表。 -- ============================================================================