← back to Greenland Onboard

scripts/refresh-products.sh

16 lines

#!/bin/bash
# Regenerate public/products.json from dw_unified.greenland_catalog (full DW+mfr detail).
# Run after any catalog change; the static :9973 viewer reads this file.
set -euo pipefail
cd "$(dirname "$0")/.."
psql "${DATABASE_URL:-postgresql://localhost/dw_unified}" -tAc "
select json_agg(json_build_object(
  'dw_sku', dw_sku, 'mfr_sku', mfr_sku, 'pattern', pattern_name, 'color', color_name,
  'collection', collection, 'material', material, 'use', use, 'width', width, 'width_in', width_inches,
  'fire_rating', fire_rating_us, 'backing', backing, 'repeat', pattern_repeat, 'min_order', minimum_order,
  'composition', composition, 'weight', weight, 'image', image_url, 'url', product_url,
  'desc', ai_description, 'hex', color_hex, 'created_at', first_seen_at
) order by dw_sku)
from greenland_catalog;" > public/products.json
echo "refreshed public/products.json ($(node -e 'console.log(require("./public/products.json").length)') rows)"