From bc441c15347eef863f3ab1b2300856c1ef26dc40 Mon Sep 17 00:00:00 2001 From: Accusys Date: Mon, 5 Oct 2026 01:06:27 +0800 Subject: [PATCH] feat(runner): add schema_version skip logic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **目的**: - 當 schema_migrations >= 42 筆時,跳過 migration 執行 - 支援 schema.sql 快速部署 **邏輯**: - 檢查 schema_migrations 記錄數 - 如果 >= 42,表示已完整套用 - 記錄日誌並返回 **配合 M4**: - schema.sql 已驗證可用 - Worker 可正常啟動 - 42 個 migration 標記已完成 **驗證**: - M5Max128 測試通過 - Worker 啟動成功 --- src/core/db/postgres_db.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/core/db/postgres_db.rs b/src/core/db/postgres_db.rs index 59ad88b4..52ee8bb5 100644 --- a/src/core/db/postgres_db.rs +++ b/src/core/db/postgres_db.rs @@ -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)