From 1642a4b817825f6d62e2814ae15ed7dc18be5b86 Mon Sep 17 00:00:00 2001 From: Accusys Date: Wed, 13 May 2026 22:05:53 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20reply=20to=20M4=20release=20fixes=20?= =?UTF-8?q?=E2=80=94=20pre-clean=20all=20tables=20+=20SCHEMA=20variable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-05-13_release_fixes_response.md | 35 +++ .../2026-05-13_release_sop_draft.md | 283 ++++++++++++++++++ 2 files changed, 318 insertions(+) create mode 100644 docs_v1.0/M4_workspace/2026-05-13_release_fixes_response.md create mode 100644 docs_v1.0/M4_workspace/2026-05-13_release_sop_draft.md diff --git a/docs_v1.0/M4_workspace/2026-05-13_release_fixes_response.md b/docs_v1.0/M4_workspace/2026-05-13_release_fixes_response.md new file mode 100644 index 0000000..bd1d967 --- /dev/null +++ b/docs_v1.0/M4_workspace/2026-05-13_release_fixes_response.md @@ -0,0 +1,35 @@ +# Release Fixes — 回覆 + +**Date**: 2026-05-13 +**From**: M5 +**To**: M4 +**Ref**: `2026-05-13_release_fixes_required.md` + +--- + +## 修正 + +| # | 問題 | 狀態 | Commit | +|---|------|:--:|--------| +| 1 | pre-clean 只清 identities,缺其他 table | ✅ | `6cd41ed` | +| 2 | deploy.sh schema 寫死 `dev.`,無法對 public 部署 | ✅ 加 `SCHEMA` 變數 | `6cd41ed` | +| 3 | SOP schema migration 缺 `file_uuid` column | ✅ | `6cd41ed` | + +## 使用方式 + +```bash +# dev schema (預設) +bash deploy.sh + +# public schema (production) +SCHEMA=public bash deploy.sh +``` + +## Release 現狀確認 + +| 項目 | 狀態 | +|------|:--:| +| aeed7134 deploy to public | ✅ 已由 M4 手動完成 | +| 23b1c87 deploy to public | ⏳ M4 待執行(可用 `SCHEMA=public bash deploy.sh`) | +| Binary deployed | ✅ | +| Schema migration | ✅ `chunks→chunk` + `file_uuid` column | diff --git a/docs_v1.0/M4_workspace/2026-05-13_release_sop_draft.md b/docs_v1.0/M4_workspace/2026-05-13_release_sop_draft.md new file mode 100644 index 0000000..6c9c6b5 --- /dev/null +++ b/docs_v1.0/M4_workspace/2026-05-13_release_sop_draft.md @@ -0,0 +1,283 @@ +# Release SOP — Dev → Production (3002) + +**Date**: 2026-05-13 +**Version**: 2.0 +**Status**: Draft — M5 Review Required + +--- + +## 1. Prerequisites + +### 必須確認 + +| # | 檢查項 | 方法 | 門檻 | +|:--:|------|------|:--:| +| 1 | Dev (3003) 39/39 API test | `bash api_test.sh` | ✅ 39/39 | +| 2 | 檔案內容包匯入成功 | 9 tables all > 0 | ✅ 通過 | +| 3 | TMDB identities 匹配 | `SELECT * FROM dev.identities WHERE source='tmdb'` | ✅ 7 actors | +| 4 | TKG 到位 | tkg_nodes + tkg_edges > 0 | ✅ 通過 | +| 5 | Release binary 已編譯 | `cargo build --release --bin momentry` | ✅ 成功 | +| 6 | `.env.development` 切換確認 | `DATABASE_SCHEMA=public` | ✅ | + + +## 2. Backup + +### 2.1 Database + +```bash +BACKUP_DIR="/Users/accusys/momentry_core_releases/backup_$(date +%Y%m%d_%H%M)" +mkdir -p "$BACKUP_DIR" + +# Full public schema dump +pg_dump -U accusys -d momentry --schema=public \ + --no-owner --no-acl \ + > "$BACKUP_DIR/public_schema_full.sql" + +# Data-only dump (smaller, faster restore) +pg_dump -U accusys -d momentry --schema=public \ + --data-only --no-owner --no-acl \ + > "$BACKUP_DIR/public_schema_data.sql" + +echo "Backup: $BACKUP_DIR" +``` + +### 2.2 Binary + +```bash +cp /path/to/release/momentry "$BACKUP_DIR/momentry_$(date +%Y%m%d)" +``` + +### 2.3 Release Info + +```bash +echo "Release: v1.0.0" > "$BACKUP_DIR/RELEASE_INFO.txt" +echo "Date: $(date)" >> "$BACKUP_DIR/RELEASE_INFO.txt" +echo "Binary: $(ls -la target/release/momentry)" >> "$BACKUP_DIR/RELEASE_INFO.txt" +echo "Schema: public" >> "$BACKUP_DIR/RELEASE_INFO.txt" +``` + + +## 3. Schema Migration + +### 3.1 Apply Migration + +```sql +-- Add file_uuid column to identities (if deploying from pre-v2.0 package) +ALTER TABLE public.identities ADD COLUMN IF NOT EXISTS file_uuid VARCHAR(64); + +-- Rename chunks → chunk (v2.0 schema change) +ALTER TABLE IF EXISTS public.chunks RENAME TO chunk; + +-- Drop deprecated columns +ALTER TABLE public.chunk DROP COLUMN IF EXISTS old_chunk_id; +ALTER TABLE public.chunk DROP COLUMN IF EXISTS chunk_index; + +-- Add new columns (v1.0.3+) +ALTER TABLE public.face_detections ADD COLUMN IF NOT EXISTS timestamp_secs float8; +``` + +### 3.2 Verify Schema + +```sql +SELECT column_name, data_type +FROM information_schema.columns +WHERE table_schema = 'public' AND table_name = 'chunk' +ORDER BY ordinal_position; +``` + +Expected: 24 columns, no `old_chunk_id`, no `chunk_index`. + + +## 4. Deploy Package + +### 4.1 Deploy via deploy.sh + +```bash +cd path/to/package/ +PG_BIN="/opt/homebrew/opt/postgresql@18/bin" \ +DB_NAME="momentry" DB_USER="accusys" \ +DATABASE_SCHEMA=public \ +bash deploy.sh +``` + +### 4.2 Manual Verification (after deploy) + +```sql +SELECT 'chunk' as tbl, count(*) FROM public.chunk WHERE file_uuid = '{uuid}'; +SELECT 'identities (tmdb)', count(*) FROM public.identities WHERE source = 'tmdb'; +SELECT 'tkg_nodes', count(*) FROM public.tkg_nodes WHERE file_uuid = '{uuid}'; +SELECT 'tkg_edges', count(*) FROM public.tkg_edges WHERE file_uuid = '{uuid}'; +``` + +Expected: chunk > 0, identities > 0, tkg_nodes > 0, tkg_edges > 0. + +### 4.3 Set Status + +```sql +UPDATE public.videos SET status = 'completed' WHERE file_uuid IN ( + 'aeed71342a899fe4b4c57b7d41bcb692', + '23b1c872379d4ec06479e5ed39eef4c5' +); +``` + + +## 5. Binary Swap & Restart + +### 5.1 Stop Old Server + +```bash +# Graceful stop +pkill -TERM momentry +sleep 5 + +# Force if needed +pkill -9 momentry 2>/dev/null +``` + +### 5.2 Deploy New Binary + +```bash +cp target/release/momentry /path/to/production/binary +chmod +x /path/to/production/binary +``` + +### 5.3 Start New Server + +```bash +DATABASE_SCHEMA=public /path/to/production/binary server --port 3002 +# or with .env +MOMENTRY_SERVER_PORT=3002 DATABASE_SCHEMA=public cargo run --release -- server +``` + +### 5.4 Health Check + +```bash +curl http://localhost:3002/health +# Expected: {"status":"ok","version":"1.0.0","build_git_hash":"..."} +``` + + +## 6. Verification + +### 6.1 API Tests + +```bash +API_KEY="muser_68600856036340bcafc01930eb4bd839_1774418104_97221b69" +HOST="http://localhost:3002" + +# Health +curl "$HOST/health" +curl "$HOST/health/detailed" + +# Files +curl -H "X-API-Key: $API_KEY" "$HOST/api/v1/files?page=1&page_size=5" +curl -H "X-API-Key: $API_KEY" "$HOST/api/v1/files/scan" + +# Search +curl -X POST -H "X-API-Key: $API_KEY" -H "Content-Type: application/json" \ + -d '{"query":"Audrey Hepburn","uuid":"aeed71342a899fe4b4c57b7d41bcb692","limit":3}' \ + "$HOST/api/v1/search/universal" + +# Identities +curl -H "X-API-Key: $API_KEY" "$HOST/api/v1/identities?page=1&page_size=5" + +# Chunk detail (v1.0.3+) +curl -H "X-API-Key: $API_KEY" "$HOST/api/v1/file/aeed71342a899fe4b4c57b7d41bcb692/chunk/0" + +# Face trace +curl -X POST -H "X-API-Key: $API_KEY" -H "Content-Type: application/json" \ + -d '{"sort_by":"face_count","limit":3}' \ + "$HOST/api/v1/file/aeed71342a899fe4b4c57b7d41bcb692/face_trace/sortby" + +# Trace video +curl -o /dev/null -w "%{http_code}" -H "X-API-Key: $API_KEY" \ + "$HOST/api/v1/file/aeed71342a899fe4b4c57b7d41bcb692/trace/1934/video?padding=1" +# Expected: 200 + +# Full test suite +bash api_test.sh +# Expected: 39/39 +``` + +### 6.2 Portal Check + +| Page | URL | Expect | +|------|-----|--------| +| FilesView | `http://localhost:1420/files` | Charade = ✅ 已就绪 | +| SearchView | `http://localhost:1420/search` | File dropdown has Charade | +| Trace View | File → Traces | Face list visible | +| Video Playback | Search → Play | Video plays | + +### 6.3 Demo + +```bash +DEMO_BASE="http://localhost:3002" \ +DEMO_FILE="aeed71342a899fe4b4c57b7d41bcb692" \ +python3 scripts/demo_runner.py API_V1.0.0/DEMO_SCRIPT_v1.0.0.json --auto --speed 0.03 + +# Expected: 21/21 steps passed +``` + + +## 7. Rollback + +### 7.1 Binary Rollback + +```bash +pkill momentry +cp "$BACKUP_DIR/momentry_$(date +%Y%m%d)" /path/to/production/binary +DATABASE_SCHEMA=public /path/to/production/binary server --port 3002 +``` + +### 7.2 Schema Rollback + +```sql +-- Rename back if needed +ALTER TABLE public.chunk RENAME TO chunks; +``` + +### 7.3 Data Rollback + +```bash +psql -U accusys -d momentry < "$BACKUP_DIR/public_schema_full.sql" +``` + +### 7.4 Downtime Estimation + +| Step | Est. Time | +|------|:--------:| +| Backup | 2 min | +| Schema migration | 1 min | +| Package deploy | 5-10 min | +| Binary swap | 1 min | +| Verification | 5 min | +| **Total** | **~15-20 min** | + + +## 8. Decision Log + +| # | Decision | Owner | Decision | +|---|----------|:--:|------| +| 1 | Production binary source | M5 | M5 提供 release binary or M4 自編譯 | +| 2 | Schema: rename chunks→chunk? | M5 | M5 決定 public schema 結構 | +| 3 | Identity merge strategy | M5 | Keep prod 15 TMDB + merge with dev data? | +| 4 | Downtime window | M5 | 維護模式 (403 all) or hard stop? | +| 5 | Release scope | M5 | `aeed7134` only or both HD + YouTube? | +| 6 | .env / config for public schema | M5 | Production binary reads `DATABASE_SCHEMA=public` | + +--- + +## Appendix: Release Checklist + +- [ ] Dev 3003 passed all tests (39/39 + demo 21/21) +- [ ] Production old binary backed up +- [ ] Production DB full backup +- [ ] Schema migration SQL ready +- [ ] Package deployed to public schema +- [ ] Status set to completed +- [ ] New binary deployed +- [ ] Server restarted on 3002 +- [ ] Health check returns ok +- [ ] 39/39 API tests pass on 3002 +- [ ] Portal shows files correctly +- [ ] Demo runs 21/21 on 3002