diff --git a/.gitea/workflows/run-migration.yml b/.gitea/workflows/run-migration.yml index 38c9ba3f8..3ed3ad85d 100644 --- a/.gitea/workflows/run-migration.yml +++ b/.gitea/workflows/run-migration.yml @@ -57,12 +57,18 @@ jobs: - name: Identify new migrations id: diff run: | - NEW_FILES=$(git diff --name-only --diff-filter=A HEAD~1 HEAD -- 'apps/api/migrations/*.sql' || true) + ALL_NEW_FILES=$(git diff --name-only --diff-filter=A HEAD~1 HEAD -- 'apps/api/migrations/*.sql' || true) + NEW_FILES=$(echo "$ALL_NEW_FILES" | grep -Ev '(_down|rollback)\.sql$' || true) + SKIPPED_ROLLBACK_FILES=$(echo "$ALL_NEW_FILES" | grep -E '(_down|rollback)\.sql$' || true) echo "new_files<> $GITHUB_OUTPUT echo "$NEW_FILES" >> $GITHUB_OUTPUT echo "EOF" >> $GITHUB_OUTPUT echo "=== New migration files ===" echo "$NEW_FILES" + if [ -n "$SKIPPED_ROLLBACK_FILES" ]; then + echo "=== Rollback/down migrations skipped by design ===" + echo "$SKIPPED_ROLLBACK_FILES" + fi - name: Apply new migrations if: steps.diff.outputs.new_files != '' @@ -133,8 +139,7 @@ jobs: psql "$url" \ -v ON_ERROR_STOP=1 \ -v commit_sha="${{ github.sha }}" \ - -v files_json="$FILES_JSON" \ - -c " + -v files_json="$FILES_JSON" <<'SQL' INSERT INTO asset_discovery_run ( run_id, triggered_by, scope, scan_depth, status, started_at, ended_at, tools_used, summary @@ -153,7 +158,7 @@ jobs: 'files', :'files_json'::jsonb ) ); - " + SQL } audit_err="$(mktemp)" diff --git a/docs/LOGBOOK.md b/docs/LOGBOOK.md index ad134a990..600b8e1da 100644 --- a/docs/LOGBOOK.md +++ b/docs/LOGBOOK.md @@ -6307,6 +6307,29 @@ RLS app context: project_context=awoooi total=312 redacted_total=0 envelope_total=0 ``` +**Migration CI 紅燈修正**: + +- 首次推版後 `run-migration.yml` run `1914` 失敗在 `Seed asset_discovery_run (audit)`: + - `psql -c` 不展開 `:'commit_sha'` / `:'files_json'` 變數,造成 syntax error。 + - 同一 workflow 也把 `_down.sql` 當新增 migration 套用,導致 up migration 後又被 rollback。 +- 已手動確認 production 欄位曾被 `_down.sql` 移除,並立即重新套回 up migration。 +- workflow 修正: + - `Identify new migrations` 跳過 `*_down.sql` / `*rollback.sql`。 + - audit SQL 改用 heredoc 餵給 `psql`,讓 `-v` 變數正常展開。 + +```text +ruby YAML.load_file(".gitea/workflows/run-migration.yml") +# yaml ok + +bash -n Identify new migrations / Seed asset_discovery_run extracted scripts +# bash syntax ok + +Identify new migrations local dry-run: +apps/api/migrations/awooop_phase7_outbound_truth_chain_columns_2026-05-12.sql +Rollback/down migrations skipped: +apps/api/migrations/awooop_phase7_outbound_truth_chain_columns_2026-05-12_down.sql +``` + **下一步**: - 推 Gitea main,讓 API image 部署 T1 程式碼。