← back to Dw Yolo Loop

scripts/kravet-master-2026/sync_authoritative_mac2_to_kamatera.sh

21 lines

#!/usr/bin/env bash
# Split-brain fix: the broad Kravet MAP master (kravet_authoritative_pricing, 44,734 SKUs,
# Mar+Apr 2026 sheets) was built on Mac2's LOCAL dw_unified but never existed on Kamatera
# (canonical) — which is where the shopify_api_queue write-path runs. This copies it over,
# additively (CREATE IF NOT EXISTS, no DROP). Keyed by mfr_sku -> joins live shopify_products.
# Pair with kravet_master_price_2026 (Jan-2026, carries unit_of_measure) for the ROLL-only guard.
set -euo pipefail
CSV=/tmp/kravet_auth_pricing.csv
PGHOST=/tmp psql -d dw_unified -c "\copy (select mfr_sku,old_whls,old_map,new_whls,new_map,source,loaded_at from kravet_authoritative_pricing) to '$CSV' with (format csv, header true)"
scp -q "$CSV" my-server:"$CSV"
ssh my-server "psql -U dw_admin -d dw_unified -h 127.0.0.1 -v ON_ERROR_STOP=1 <<'SQL'
CREATE TABLE IF NOT EXISTS kravet_authoritative_pricing (
  mfr_sku text PRIMARY KEY, old_whls numeric, old_map numeric,
  new_whls numeric, new_map numeric, source text, loaded_at timestamptz
);
\copy kravet_authoritative_pricing FROM '$CSV' WITH (FORMAT csv, HEADER true)
CREATE INDEX IF NOT EXISTS idx_kap_mfr_upper ON kravet_authoritative_pricing (upper(mfr_sku));
ANALYZE kravet_authoritative_pricing;
SQL"
ssh my-server "psql -U dw_admin -d dw_unified -h 127.0.0.1 -tA -c \"select count(*) from kravet_authoritative_pricing;\""