feat(runner): add schema_version skip logic

**目的**:
- 當 schema_migrations >= 42 筆時,跳過 migration 執行
- 支援 schema.sql 快速部署

**邏輯**:
- 檢查 schema_migrations 記錄數
- 如果 >= 42,表示已完整套用
- 記錄日誌並返回

**配合 M4**:
- schema.sql 已驗證可用
- Worker 可正常啟動
- 42 個 migration 標記已完成

**驗證**:
- M5Max128 測試通過
- Worker 啟動成功
This commit is contained in:
Accusys
2026-10-05 01:06:27 +08:00
parent 8b1efb307b
commit bc441c1534
+14
View File
@@ -1071,6 +1071,20 @@ impl PostgresDb {
// ── Schema Migrations (tracking table, used by health check) ──
sqlx::query("CREATE TABLE IF NOT EXISTS schema_migrations (id SERIAL PRIMARY KEY, filename TEXT NOT NULL UNIQUE, checksum TEXT NOT NULL, applied_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), duration_ms INTEGER DEFAULT 0)").execute(pool).await?;
// ── Check if schema.sql was applied (skip migrations if so) ──
let applied_count: i64 = sqlx::query_scalar(
"SELECT COUNT(*) FROM schema_migrations"
)
.fetch_one(pool)
.await
.unwrap_or(0);
if applied_count >= 42 {
tracing::info!("Schema already fully applied ({} migrations), skipping migration files", applied_count);
tracing::info!("This indicates schema.sql was used for initial setup");
return Ok(());
}
// ── Videos ──
// ─────────────────────────────────────────────────────────────────────────────
// DISABLED: Hardcoded DDL (moved to migrations/*.sql)