← back to Dw Sku Integrity
fire-self-copy.sh
29 lines
#!/usr/bin/env bash
# TK-10896 — guarded fire loop for the 18 remaining canonical self-copy vendors.
# GATED: this writes canonical Kamatera dw_unified.dw_sku. STEVE runs this himself.
# Per vendor: preflight (must be GO) -> apply -> verify -> ledger. Canary-first
# (smallest vendors first). Every write is idempotent (blank-guard), shopify_id-keyed,
# recover-existing-code (no mint), reversible (apply-plans-canonical/<v>/undo.sql).
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
VENDORS=$(python3 -c "
import json
d=json.load(open('apply-plans-canonical/SUMMARY.json'))['per_vendor']
print(' '.join(s for n,s in sorted((v['statements'],v['slug']) for v in d.values()) if s!='arte-international'))
")
printf '%-26s %-8s %5s %6s %-6s\n' VENDOR PREFLIGHT APPLY VERIFY RESULT
for V in $VENDORS; do
PV=$(node preflight-check.mjs --plan-dir apply-plans-canonical --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-canonical/$V/apply.sql" 2>&1 | grep -c '^UPDATE')
VF=$(node preflight-check.mjs --plan-dir apply-plans-canonical --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-10896","action":"self-copy canonical dw_sku %s (%s rows, no mint)","blast_radius":%s,"undo_cmd":"ssh root@45.61.58.125 \\"psql dw_unified\\" < ~/Projects/dw-sku-integrity/apply-plans-canonical/%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 any vendor: ssh root@45.61.58.125 \"psql dw_unified\" < apply-plans-canonical/<vendor>/undo.sql ---"