#!/bin/bash # Restores roles.sql/schema.sql/data.sql (from 01-dump-old.sh) into the NEW self-hosted # Postgres. Run this ON the Cloud Server, from /opt/caterium-supabase, after `docker # compose up -d` has the db container healthy. set -euo pipefail DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" DUMPS_DIR="$DIR/dumps" [ -f "$DIR/.env" ] && set -a && . "$DIR/.env" && set +a : "${POSTGRES_PASSWORD:?POSTGRES_PASSWORD missing — check .env}" NEW_DB_URL="postgres://postgres:${POSTGRES_PASSWORD}@127.0.0.1:5432/postgres" for f in roles.sql schema.sql data.sql; do [ -f "$DUMPS_DIR/$f" ] || { echo "Missing $DUMPS_DIR/$f — run 01-dump-old.sh first" >&2; exit 1; } done echo "== Restoring roles ==" # Managed Supabase pre-creates supabase_admin/authenticator/etc; the self-hosted image # does too, so role-creation conflicts here are expected and safe to ignore. psql "$NEW_DB_URL" -v ON_ERROR_STOP=0 -f "$DUMPS_DIR/roles.sql" || true echo "== Restoring schema (public + auth + storage structures, RLS, functions, triggers, grants) ==" psql "$NEW_DB_URL" -v ON_ERROR_STOP=1 -f "$DUMPS_DIR/schema.sql" echo "== Restoring data ==" psql "$NEW_DB_URL" -v ON_ERROR_STOP=1 -f "$DUMPS_DIR/data.sql" echo "" echo "Restore complete. Next: psql against NEW_DB_URL with scripts/03-verify-counts.sql" echo "and compare against the OLD counts captured by 01-dump-old.sh." echo "" echo "NEW_DB_URL=$NEW_DB_URL"