← back to Maya Width Fix
restore.py
16 lines
#!/usr/bin/env python3
# UNDO: restore original (polluted) width + width_inches for every row in the restore-map.
import json, subprocess, sys, glob
path=sys.argv[1] if len(sys.argv)>1 else sorted(glob.glob("/Users/macstudio3/Projects/maya-width-fix/restore-map-*.json"))[-1]
rm=json.load(open(path))
PSQL=["psql","-h","/tmp","-d","dw_unified","-At","-c"]
def esc(s): return (s or "").replace("'","''")
n=0
for r in rm["restore_map"]:
wi = f"width_inches = {r['old_width_inches']}" if r.get('old_width_inches') else "width_inches = NULL"
sql=f"UPDATE maya_catalog SET width='{esc(r['old_width'])}', {wi} WHERE dw_sku='{esc(r['dw_sku'])}';"
res=subprocess.run(PSQL+[sql],capture_output=True,text=True)
if res.returncode!=0: print("ERR",r['dw_sku'],res.stderr); sys.exit(1)
n+=1
print(f"restored {n} rows from {path}")