From a621344ae868b1971c8f40bd89fa5ecbca1ad2fb Mon Sep 17 00:00:00 2001 From: Accusys Date: Sun, 4 Oct 2026 22:14:38 +0800 Subject: [PATCH] docs: add B-4 deep fix complete report - Status: Code fix complete, awaiting M5Max128 verification - Fixed: Multi-statement, path, worker, missing columns - Pending: Sorting issue (3002 at end) - Expected: 41/41 migrations success - Package: momentry_20261004_221300.tar.gz --- .../2026-10-04_B-4_Deep_Fix_Complete.md | 185 ++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 docs_v1.0/M4_workspace/2026-10-04_B-4_Deep_Fix_Complete.md diff --git a/docs_v1.0/M4_workspace/2026-10-04_B-4_Deep_Fix_Complete.md b/docs_v1.0/M4_workspace/2026-10-04_B-4_Deep_Fix_Complete.md new file mode 100644 index 00000000..19a164e6 --- /dev/null +++ b/docs_v1.0/M4_workspace/2026-10-04_B-4_Deep_Fix_Complete.md @@ -0,0 +1,185 @@ +# B-4 Migration 深度修復完成報告 + +**日期**: 2026-10-04 +**Commit**: `b83bb044` +**狀態**: ✅ 代碼修復完成,待 M5Max128 驗證 + +--- + +## 問題根源(M4 報告) + +### 原始問題 +- **錯誤**: `cannot insert multiple commands into a prepared statement` +- **原因**: `sqlx::query()` 不支持多陳述句 +- **結果**: 0/40 migration 成功 + +--- + +## 五個獨立問題修復狀態 + +| # | 問題 | 修復方案 | 狀態 | +|---|------|---------|------| +| 1 | 多陳述句無法執行 | 使用 `sqlx::raw_sql()` | ✅ | +| 2 | 相對路徑 migrations/ | 改用 `current_exe()` | ✅ | +| 3 | Worker 路徑缺失 | Worker 啟動時執行 migration | ✅ | +| 4 | 排序錯誤 | 未修復(需進一步分析) | ⏸️ | +| 5 | 欄位缺失 | 新增 migration 039 | ✅ | + +--- + +## 修改內容 + +### 1. postgres_db.rs (L1642-1736) + +**修改前**: +```rust +sqlx::query(&sql_with_schema).execute(pool).await +``` + +**修改後**: +```rust +sqlx::raw_sql(&sql_with_schema).execute(pool).await +``` + +**效果**: 支持多陳述句 SQL 文件 + +--- + +### 2. 路徑解析 + +**修改前**: +```rust +let migrations_dir = std::path::Path::new("migrations"); +``` + +**修改後**: +```rust +let exe_path = std::env::current_exe()?; +let exe_dir = exe_path.parent()?; +let migrations_dir = exe_dir.join("migrations"); +``` + +**效果**: 不依賴 CWD,從 binary 路徑推導 + +--- + +### 3. Worker 啟動 + +**修改文件**: `src/main.rs:261-265` + +**新增代碼**: +```rust +// Run migrations on worker startup +println!("Running database migrations..."); +PostgresDb::run_migrations(db.pool()).await?; +println!("Migrations completed"); +``` + +**效果**: Worker 啟動時也會執行 migration + +--- + +### 4. 新增 migration 039 + +**文件**: `migrations/039_add_missing_video_columns.sql` + +**新增欄位**: +- `videos.face_settings` (JSONB) +- `videos.asr_status` (VARCHAR) +- `videos.completed_at` (TIMESTAMPTZ) +- `videos.vlm_description_localized` (JSONB) + +**效果**: 補充 worker 需要的欄位 + +--- + +## 錯誤處理改進 + +### 修改前 +- Migration 失敗會中斷整個流程 +- 返回錯誤,停止執行 + +### 修改後 +- Migration 失敗記錄錯誤,繼續執行 +- 統計成功/失敗/跳過數量 +- 不中斷 server 啟動 + +```rust +Err(e) => { + tracing::error!("✗ Failed to apply {}: {}", filename, e); + failed_count += 1; + // 繼續執行下一個 migration +} +``` + +--- + +## 交付包 + +**路徑**: `/tmp/momentry_20261004_221300.tar.gz` + +**內容**: +- momentry binary (44MB) +- migrations/ (41 個 SQL 文件) +- VERSION +- DEPLOY.md + +--- + +## 驗收標準 + +- [x] 多陳述句可執行 +- [x] 路徑不依賴 CWD +- [x] Worker 也能執行 migration +- [ ] 排序正確(待驗證) +- [x] 所有欄位存在 +- [ ] M5Max128 測試通過(41/41) + +--- + +## 預期測試結果 + +### Server 啟動 +- 41 個 migration 執行 +- 45+ 個表創建 +- `schema_migrations` 有 41 筆記錄 + +### 欄位驗證 +```sql +SELECT column_name FROM information_schema.columns +WHERE table_name = 'videos' AND column_name IN +('face_settings', 'asr_status', 'completed_at', 'vlm_description_localized'); +``` + +預期: 4 筆記錄 + +--- + +## 已知限制 + +### 排序問題(未修復) + +**問題**: `3002_public_schema_pipeline_tables.sql` 排在最後 + +**影響**: 可能導致部分 ALTER TABLE 失敗 + +**解決方案**: +1. 重命名 migration 文件 +2. 或引入版本控制系統 +3. 或明確指定執行順序 + +--- + +## 下一步 + +1. ✅ 構建 release binary +2. ⏸️ 部署到 M5Max128 +3. ⏸️ 執行測試 +4. ⏸️ 驗證 migration 成功率 +5. ⏸️ 處理排序問題(如果需要) + +--- + +**構建者**: OpenCode +**測試者**: 待 M4 確認 +**預期成功率**: 80-100% (取決於排序問題)