[Fix] Recover conversation migration state safely#816
[Fix] Recover conversation migration state safely#816dingyi222666 wants to merge 1 commit intoChatLunaLab:v1-devfrom
Conversation
Skip admin-only conversation checks for personal routes and persist migration completion metadata before legacy tables are purged. This lets startup recovery handle an existing legacy sentinel without re-reading missing tables or discarding existing ChatLuna data. Tests: not run (not requested)
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
💤 Files with no reviewable changes (1)
Walkthrough该PR改进了ChatLuna的房间到对话迁移流程,引入了sentinel哨兵机制支持迁移恢复,优化了权限检查逻辑,并增强了数据库清理与迁移验证功能。 Changes
Sequence Diagram(s)sequenceDiagram
participant App as 应用启动
participant FS as 文件系统
participant Migrator as 迁移器
participant DB as 数据库
participant Meta as 迁移元数据
App->>FS: 检查sentinel文件存在?
alt Sentinel存在
FS-->>Migrator: sentinel已存在
Migrator->>Meta: 检查验证结果是否已通过
alt 验证已通过
Migrator->>Meta: 更新schema_version和完成时间
Migrator-->>App: 恢复完成,跳过迁移
else 验证未通过
Migrator->>DB: 探测ChatLuna数据存在
Migrator->>Meta: 记录通过的验证结果
Migrator->>Meta: 设置完成标志和时间戳
Migrator-->>App: 迁移验证完成
end
else Sentinel不存在
FS-->>Migrator: 需执行完整迁移
Migrator->>DB: 从room/message执行迁移
Migrator->>Meta: 写入完成标志
Migrator->>DB: 清理遗留表
Migrator->>Meta: 记录迁移完成时间
Migrator->>FS: 创建sentinel文件
Migrator-->>App: 迁移完全完成
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request enhances the migration logic from legacy rooms to conversations by introducing a sentinel check and recovery mechanism to handle interrupted migrations or existing data. Key updates include refactoring metadata persistence, improving error detection for missing tables, and refining access control logic. Feedback was provided to parallelize database queries during the migration validation process to improve performance.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 97b451a961
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (existsSync(getLegacySchemaSentinel(ctx.baseDir))) { | ||
| return ensureMigrationValidated(ctx, config) |
There was a problem hiding this comment.
Avoid skipping migration on sentinel alone
This early return makes the sentinel file authoritative even when legacy chathub_* tables still contain data, so a stale sentinel (for example after restoring an old DB while keeping data/chatluna/temp/legacy-schema-disabled.json) will bypass migration entirely. In that case ensureMigrationValidated() marks validation as passed and writes migration-done metadata without reading legacy rows, leaving legacy conversations/messages unmigrated and effectively lost to ChatLuna.
Useful? React with 👍 / 👎.
|
Superseded by #817 |
This pr hardens the built-in conversation migration flow so startup recovery can safely handle an existing legacy sentinel, avoid re-reading already-purged legacy tables, and preserve current ChatLuna data.
New Features
Bug fixes
cannot resolve tableas a missing-table error during legacy cleanup.Other Changes