#!/usr/bin/env bash
# Builds the two public minimal-reproduction databases (no private source needed):
#   wcmin_before = part 1;  wcmin_after = part 1 + part 2.
# Requires roles wayclub_admin (owner) on the local experiment cluster.
set -euo pipefail
HERE=$(cd "$(dirname "$0")/.." && pwd)
PSQL=${PSQL:-/opt/homebrew/opt/postgresql@17/bin/psql}; PORT=${PGPORT_EXP:-55499}
for db in wcmin_before wcmin_after; do
  $PSQL -h localhost -p $PORT -U postgres -q -d postgres -c "drop database if exists $db with (force)" -c "create database $db owner wayclub_admin"
  $PSQL -h localhost -p $PORT -U postgres -q -d $db -c "create extension if not exists pgcrypto with schema public"
  $PSQL -h localhost -p $PORT -U wayclub_admin -d $db -q -v ON_ERROR_STOP=1 -1 -f "$HERE/sql/minimal/01_before_fix_006_excerpt.sql"
done
$PSQL -h localhost -p $PORT -U wayclub_admin -d wcmin_after -q -v ON_ERROR_STOP=1 -1 -f "$HERE/sql/minimal/02_after_fix_011_excerpt.sql"
echo "built wcmin_before, wcmin_after"
