← back to Dw Sku Integrity
fire-content-match.sh
28 lines
#!/usr/bin/env bash
# TK-10900/A — guarded fire loop for content-match recovery (Program A).
# GATED: writes canonical Kamatera dw_unified.dw_sku. STEVE runs this himself.
# Per vendor: preflight (must be GO) -> apply -> verify -> ledger. Every write is idempotent
# (blank-guard), shopify_id-keyed, recover-existing-code (no mint), reversible via
# apply-plans-content-match/<vendor>/undo.sql. Provenance-gated: only vendors Steve has ruled
# on (Carnegie=bare base code, 2026-08-31) should be passed in.
#
# Usage: ./fire-content-match.sh Carnegie [More Vendors...]
set -uo pipefail
cd ~/Projects/dw-sku-integrity
export DWSKU_PSQL='ssh root@45.61.58.125 psql dw_unified'
LEDGER=~/.claude/yolo-queue/executed-reversible/ledger.jsonl
[ "$#" -ge 1 ] || { echo "usage: $0 <Vendor> [Vendor...]"; exit 2; }
printf '%-26s %-8s %5s %6s %-6s\n' VENDOR PREFLIGHT APPLY VERIFY RESULT
for V in "$@"; do
PV=$(node preflight-check.mjs --plan-dir apply-plans-content-match --vendor "$V" 2>/dev/null | python3 -c "import sys,json;print(json.load(sys.stdin)['verdict'])")
if [ "$PV" != "GO" ]; then printf '%-26s %-8s %5s %6s %-6s\n' "${V:0:26}" "$PV" - - SKIP; continue; fi
AP=$(ssh root@45.61.58.125 "psql dw_unified" < "apply-plans-content-match/$V/apply.sql" 2>&1 | grep -c '^UPDATE')
VF=$(node preflight-check.mjs --plan-dir apply-plans-content-match --vendor "$V" --mode verify 2>/dev/null)
VV=$(echo "$VF" | python3 -c "import sys,json;print(json.load(sys.stdin)['verdict'])")
AT=$(echo "$VF" | python3 -c "import sys,json;print(json.load(sys.stdin)['ALREADY_TARGET'])")
TS=$(node -e "console.log(new Date().toISOString())")
printf '{"ts":"%s","agent":"steve-fired","ticket":"TK-10900","action":"content-match canonical dw_sku %s (%s rows, real mfr base code, no mint)","blast_radius":%s,"undo_cmd":"ssh root@45.61.58.125 \\"psql dw_unified\\" < ~/Projects/dw-sku-integrity/apply-plans-content-match/%s/undo.sql","verify":"mode=verify %s"}\n' "$TS" "$V" "$AT" "$AT" "$V" "$VV" >> "$LEDGER"
printf '%-26s %-8s %5s %6s %-6s\n' "${V:0:26}" "$PV" "$AP" "$VV" "$([ "$VV" = GO ] && echo DONE || echo CHECK)"
done
echo "--- done. undo a vendor: ssh root@45.61.58.125 \"psql dw_unified\" < 'apply-plans-content-match/<vendor>/undo.sql' ---"