← back to Enrich Local Hybrid
reconcile-staging/restore-image-less.sh
21 lines
#!/bin/bash
# restore-image-less.sh — reverses one reconcile-image-less.sh --apply run.
# Reads the snapshot JSON and restores last_error to its recorded old value
# (always NULL for this reconcile) for exactly the ids it stamped — and ONLY
# if they still carry the 'unenrichable-no-image' stamp (so we never clobber a
# row that has since been legitimately re-processed).
#
# Usage: ./restore-image-less.sh <snapshot.json>
set -euo pipefail
SNAP="${1:?usage: restore-image-less.sh <snapshot.json>}"
[ -f "$SNAP" ] || { echo "snapshot not found: $SNAP"; exit 1; }
PSQL="sudo -u postgres psql -d dw_unified -Atc"
IDS=$(grep -oE '"id":[0-9]+' "$SNAP" | grep -oE '[0-9]+' | paste -sd, -)
[ -z "$IDS" ] && { echo "snapshot has no ids — nothing to restore"; exit 0; }
N=$($PSQL "SELECT count(*) FROM enrichment_tracking WHERE id IN ($IDS) AND last_error='unenrichable-no-image'")
echo "restoring $N rows (of $(grep -c '"id":' "$SNAP") snapshotted) to last_error=NULL ..."
$PSQL "UPDATE enrichment_tracking SET last_error=NULL, updated_at=now()
WHERE id IN ($IDS) AND last_error='unenrichable-no-image'" >/dev/null
echo "done. restored $N rows."