Skip to content

Conversation

@codeunia-dev
Copy link
Owner

@codeunia-dev codeunia-dev commented Nov 27, 2025

Improve restore.sh data restoration by temporarily disabling foreign key constraints and filtering pg_restore output.

Authored by: @akshay0611

Summary by CodeRabbit

  • New Features

    • Disaster Recovery script updated to v2.0 with improved data restoration handling and constraint management.
  • Documentation

    • Enhanced documentation detailing known limitations and scope of data restoration.

✏️ Tip: You can customize this high-level summary in your review settings.

…ing foreign key constraints and filtering `pg_restore` output.
@vercel
Copy link

vercel bot commented Nov 27, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
codeunia Ready Ready Preview Comment Nov 27, 2025 6:23am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 27, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request updates a Supabase disaster recovery restore script to version 2.0, enhancing documentation with known limitations and restoration scope details. The restore_data function is refactored to disable foreign key constraints before restoring data via data-only pg_restore with improved error filtering, then re-enable constraints after restoration. SQL snapshot files contain updated token strings.

Changes

Cohort / File(s) Summary
Restore Script Updates
restore.sh
Version bumped to v2.0; documentation expanded with KNOWN LIMITATIONS and WHAT GETS RESTORED sections. restore_data function refactored to dynamically disable all public schema triggers via DO block, execute data-only pg_restore with schema filtering and permission error suppression, then re-enable triggers. Logging updated to reflect constraint handling steps.
SQL Snapshot Token Updates
supabase_snapshot/functions.sql, supabase_snapshot/schema.sql
Cryptographic token strings updated in SQL dump headers and footers. functions.sql: single token replacement. schema.sql: two token replacements in header and final section. No functional or query-level changes.

Sequence Diagram

sequenceDiagram
    participant restore as restore.sh
    participant db as PostgreSQL
    participant pgr as pg_restore

    rect rgb(240, 248, 255)
    Note over restore,db: Disable Constraints Phase
    restore->>db: Execute DO block:<br/>ALTER TABLE...DISABLE TRIGGER ALL
    db-->>restore: Triggers disabled for all public tables
    end

    rect rgb(240, 248, 255)
    Note over restore,pgr: Restore Data Phase
    restore->>pgr: Execute pg_restore<br/>--data-only --schema=public
    pgr->>db: Stream data into tables
    db-->>pgr: Permission/ownership warnings (filtered)
    pgr-->>restore: Data restoration complete
    end

    rect rgb(240, 248, 255)
    Note over restore,db: Re-enable Constraints Phase
    restore->>db: Execute DO block:<br/>ALTER TABLE...ENABLE TRIGGER ALL
    db-->>restore: Triggers re-enabled for all public tables
    end

    restore->>restore: Log success: constraints restored,<br/>data fully recovered
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • restore.sh: Requires careful validation of dynamic trigger disable/enable logic, pg_restore parameter correctness, and error filtering patterns. The constraint handling is critical to restoration integrity.
  • SQL snapshots: Token substitutions are straightforward but verification that tokens are consistent across files is necessary.
  • Key attention areas:
    • Correctness of the DO block SQL syntax for disabling/enabling triggers
    • Completeness of permission error filters in pg_restore
    • Validation that data-only restore with schema filtering doesn't skip required data

Possibly Related PRs

Poem

🐰 A restore script springs to life with triggers held tight,
Foreign keys dance away, then waltz back in delight,
V2.0 hops forward with grace and care,
Data flows freely—catastrophes beware!

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/datarestorescript

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b1e2041 and dd58337.

📒 Files selected for processing (3)
  • restore.sh (3 hunks)
  • supabase_snapshot/functions.sql (1 hunks)
  • supabase_snapshot/schema.sql (2 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codeunia-dev codeunia-dev merged commit 31791f8 into main Nov 27, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants