caterium-app/ops/supabase-selfhosted/scripts/02-restore-new.sh
pavlov346346 88b7f55db4 Ops: add self-hosted Supabase stack for Timeweb Cloud migration
Full production-ready docker-compose stack (db, kong, auth, rest,
realtime, storage, imgproxy, meta, functions, studio) targeting
api.caterium.ru, plus bootstrap script for a fresh Cloud Server,
Caddy reverse-proxy config (HTTPS, WebSocket, upload limits), and
dump/restore/verify/storage-sync scripts for moving off the managed
Supabase project (cksuehzcimitsxmeloes). Does not touch public/ or
any live runtime behavior — frontend cutover is documented separately
in frontend-cutover.md and only applied after Etap 8 verification.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-11 16:20:45 +03:00

34 lines
1.4 KiB
Bash

#!/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"