diff --git a/restore.sh b/restore.sh index 2795f9e4..d63b7bb2 100755 --- a/restore.sh +++ b/restore.sh @@ -1,12 +1,12 @@ #!/bin/bash ################################################################################ -# Supabase Disaster Recovery - Restore Script +# Supabase Disaster Recovery - Restore Script (v2.0) ################################################################################ # This script restores a complete Supabase database backup including: # - Extensions # - Schema (tables, indexes, constraints, relations) -# - Full data +# - Full data (with limitations - see below) # - SQL Functions # - Triggers # - RLS Policies @@ -16,6 +16,21 @@ # ./restore.sh # # IMPORTANT: This should be run on a NEW/EMPTY Supabase project +# +# KNOWN LIMITATIONS: +# - auth.users data cannot be restored (Supabase managed schema) +# - Tables with FK to auth.users may have partial data restoration +# - Users will need to re-register or be imported via Supabase Admin API +# - Some permission errors are expected and filtered out +# +# WHAT GETS RESTORED: +# ✅ Complete database schema (all tables, indexes, constraints) +# ✅ All RLS policies +# ✅ All custom functions and triggers +# ✅ Data in tables without auth.users dependencies +# ⚠️ Partial data in user-dependent tables +# +# For more information, see backup_with_auth_export.sh ################################################################################ set -e # Exit on error @@ -193,19 +208,63 @@ restore_data() { exit 1 fi - # Use pg_restore with data-only mode to avoid conflicts with already-created schema - pg_restore "$SUPABASE_DB_URL" \ + log_info "Temporarily disabling foreign key constraints..." + + # Disable all foreign key constraints temporarily + psql "$SUPABASE_DB_URL" > /dev/null 2>&1 <&1 | grep -v "WARNING" || true - - if [ ${PIPESTATUS[0]} -eq 0 ]; then - log_info "✓ Data restored successfully" - else - log_warn "Data restore completed with some warnings (this is often normal)" - fi + --schema=public \ + "$BACKUP_DIR/complete_backup.dump" 2>&1 | \ + grep -v "WARNING" | \ + grep -v "permission denied.*system trigger" | \ + grep -v "must be owner" | \ + grep -v "permission denied for table" | \ + grep -v "permission denied for sequence" || true + + log_info "Re-enabling foreign key constraints..." + + # Re-enable all triggers + psql "$SUPABASE_DB_URL" > /dev/null 2>&1 <