Migration History Mismatch - Cannot Create Baseline for Existing Production Database #40721
Replies: 5 comments
|
supabase db dump -f |
|
For anyone else hitting this same wall, thats the key insight here. When your migration history is too far gone to repair, supabase db dump -f supabase/migrations/00000000000001_baseline.sql gives you a complete snapshot of your current production schema as a single file. This bypasses the migration tracking entirely and just captures what actually exists in the database right now. After creating that baseline, you'll want to clear the migration history on remote with DELETE FROM supabase_migrations.schema_migrations; and then push your new baseline so Supabase knows thats your starting point going forward (https://supabase.com/docs/guides/cli/managing-environments). From there your local and remote are back in sync and db diff will work normally for future changes. The frustrating part is theres no built in "force pull" or "ignore history" flag in the CLI for these brownfield scenarios. Your suggestion about better tooling for inherited projects is valid, this comes up often enough that it probably deserves a dedicated command or at least clearer docs. The strict matching requirement makes sense for teams with clean histories but becomes a blocker when youre taking over something messy. |
|
I am running into the exact same issue. My local migration history drifted from the remote database after some early manual changes, and Supabase started treating a number of already-applied migrations as missing or failed. I ended up doing something very similar: iterating through the known migration versions and repairing them as applied since the schema already existed in Postgres. After that, It feels like the core problem is that there is no clean way to tell Supabase “the schema is correct, the migration history is just out of sync” without manually repairing state. Some kind of official workflow or guardrails here would help a lot, especially since this seems easy to hit on long-lived projects. Is this the recommended recovery path, or just the least bad option available right now? |
|
I am on the same boat: https://github.com/orgs/supabase/discussions/41806 |
|
https://supabase.com/docs/guides/troubleshooting/new-branch-doesnt-copy-database This Might Help. ☝🏻 |
Uh oh!
There was an error while loading. Please reload this page.
`# Migration History Mismatch - Cannot Create Baseline for Existing Production Database
Problem Description
I have an existing production Supabase project that has been running for several months. I'm trying to set up proper local development with migrations, but I'm facing a migration history mismatch that prevents me from creating a baseline or pulling the schema.
Current Situation
Production Database
Local Repository
supabase/migrations/What I've Tried
1. Using
supabase db pull2. Starting Fresh Locally
$ supabase stop $ supabase start Starting database... Initialising schema... Stopping containers... error running container: exit 1The local Supabase fails to start, likely due to the 118 migration files trying to apply.
3. Creating New Migrations Directory
migrations_backup_[timestamp]migrations/directorysupabase db pull- still fails with same mismatch errorThe Core Issue
schema_migrationstabledb pullrequires perfect matchWhat I Need
A way to either:
Environment Details
Expected Behavior
Should be able to create a baseline migration from an existing production database even when local migration files don't perfectly match the production migration history. This is a common scenario when:
Actual Behavior
Complete inability to establish local development environment or create proper migration baseline due to strict migration history matching requirement.
Related Issues/Discussions
Reproduction Steps
supabase db pullAdditional Context
This appears to be a gap in Supabase's tooling for:
Impact: Blocking local development and proper environment separation for production application
Urgency: High - Cannot proceed with development best practices without resolution
Use Case: Establishing proper dev/staging/production environment separation for existing production database`
All reactions