M7-10 P1 | 旧数据迁移:补全 scopeType + scopeId(23 个旧会话) #78

Closed
opened 2026-06-06 16:21:28 +08:00 by wangdl · 1 comment
Owner

目标

历史 ChatSession 数据补全 scope 字段。

迁移

UPDATE ChatSession 
SET scopeType = 'knowledge_base',
    scopeId = knowledgeBaseId,
    parentKnowledgeBaseId = knowledgeBaseId
WHERE scopeType IS NULL;

验收

  • 所有旧会话 scopeType = knowledge_base
  • scopeId = knowledgeBaseId
  • prisma db push 后迁移脚本执行成功
## 目标 历史 ChatSession 数据补全 scope 字段。 ## 迁移 ```sql UPDATE ChatSession SET scopeType = 'knowledge_base', scopeId = knowledgeBaseId, parentKnowledgeBaseId = knowledgeBaseId WHERE scopeType IS NULL; ``` ## 验收 - 所有旧会话 scopeType = knowledge_base - scopeId = knowledgeBaseId - prisma db push 后迁移脚本执行成功
wangdl added this to the M7:ChatScope 会话系统 — 学习对象绑定的上下文会话 milestone 2026-06-06 16:21:28 +08:00
wangdl changed title from M7-10 P2 | 旧数据迁移:补全 scopeType + scopeId to M7-10 P1 | 旧数据迁移:补全 scopeType + scopeId(23 个旧会话) 2026-06-06 16:27:24 +08:00
Author
Owner

完成情况

交付物

prisma/migrations/backfill_chat_scope.sql:

UPDATE "ChatSession" SET
  "scopeType" = knowledge_base,
  "scopeId" = "knowledgeBaseId",
  "parentKnowledgeBaseId" = "knowledgeBaseId",
  "createdFrom" = legacy_migration,
  "lastMessageAt" = COALESCE("lastMessageAt", "updatedAt")
WHERE "scopeId" IS NULL
  AND "scopeType" = knowledge_base;

特性

  • 幂等:只更新 scopeId IS NULL 的记录,可重复执行
  • 安全:WHERE 条件限定只有默认 scopeType 的旧记录
  • 验证 SQL 已注释在脚本中

执行方式

登录服务器后运行:

npx prisma db execute --file prisma/migrations/backfill_chat_scope.sql
## 完成情况 ### 交付物 `prisma/migrations/backfill_chat_scope.sql`: ```sql UPDATE "ChatSession" SET "scopeType" = knowledge_base, "scopeId" = "knowledgeBaseId", "parentKnowledgeBaseId" = "knowledgeBaseId", "createdFrom" = legacy_migration, "lastMessageAt" = COALESCE("lastMessageAt", "updatedAt") WHERE "scopeId" IS NULL AND "scopeType" = knowledge_base; ``` ### 特性 - 幂等:只更新 scopeId IS NULL 的记录,可重复执行 - 安全:WHERE 条件限定只有默认 scopeType 的旧记录 - 验证 SQL 已注释在脚本中 ### 执行方式 登录服务器后运行: ```bash npx prisma db execute --file prisma/migrations/backfill_chat_scope.sql ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/api-server#78
No description provided.