Purpose: Establish a repeatable process for keeping staging and production databases in sync. Last Updated: 2026-01-16Documentation Index
Fetch the complete documentation index at: https://docs.encoreos.io/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This procedure ensures staging and production databases remain synchronized by:- Identifying migration differences
- Applying missing migrations to each environment
- Verifying both databases are in sync
When to Run Sync
- After applying migrations to one environment
- Before major releases
- When migration divergence is detected
- Weekly maintenance (recommended)
Prerequisites
- Supabase CLI installed and authenticated
- Access to both staging and production projects
- Backups created for both environments
Sync Process
Step 1: Identify Divergence
Step 2: Create Backups
CRITICAL: Always create backups before syncing. See:reports/database-sync-backup-instructions.md
Step 3: Apply Missing Migrations
Use the sync scripts:scripts/database-sync-complete.ps1(PowerShell)scripts/database-sync-complete.sh(Bash)
reports/database-sync-execution-guide.md
Step 4: Verify Sync
Run verification queries from:scripts/verify-database-sync.sql
Key checks:
- Migration counts match
- Migration histories identical
- Schema dumps match
- RLS policies complete
- Expected columns exist
Step 5: Test
- Run functional tests on both environments
- Verify critical workflows
- Check error logs
Prevention
To prevent future divergence:- Always apply migrations to both environments
- Use migration files, not manual SQL
- Never apply migrations directly via Dashboard without creating migration files
- Document all manual changes as migrations
Troubleshooting
Migration Conflicts
If migrations conflict:- Review both migration files
- Determine correct resolution
- Create reconciliation migration
- Apply to both environments
Missing Migration Files
If a migration exists in database but not in codebase:- Extract migration SQL from database
- Create migration file with correct timestamp
- Add to codebase
- Document in sync report
Related Documents
reports/database-sync-execution-guide.md- Detailed execution stepsreports/database-sync-backup-instructions.md- Backup proceduresscripts/verify-database-sync.sql- Verification queries