Repository navigation
feat(migrations): refuse to start against a newer (downgraded) database - #1861
Conversation
Guard against running an older binary against a database that a newer Lakekeeper has already migrated. check_migration_status only checked one direction (are the binary's migrations applied?), so an older binary — whose migrations are a subset of what's applied — reported Complete and served against the newer schema. That risks runtime errors or silent data corruption when the binary writes against schema invariants it doesn't know about. Add MigrationState::Ahead: any applied migration whose version this binary's migrator does not contain means the DB is newer. The serve gate (wait_for_db) now fails fast on Ahead instead of retrying — waiting never resolves a newer DB. Run `serve --force-start` to start anyway (emergency rollback, accepting the risk of schema incompatibility). The migrate command already aborted on this via VersionMissing; this brings serve in line.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds a new ChangesDowngrade Guard for DB-Ahead-of-Binary
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/lakekeeper-bin/src/wait_for_db.rs`:
- Around line 47-60: The migration status check is using a read pool that may be
connected to a read replica, which can have stale data if a newer Lakekeeper
binary has committed migrations to the primary but the replica hasn't replicated
them yet. This causes the status check to incorrectly report Complete instead of
Ahead, allowing an older binary to start against an incompatible schema. Replace
the read_pool passed to the check_migration_status function with a writer pool
obtained from get_writer_pool instead of get_reader_pool to ensure the migration
status check reads from the primary database and detects newer migrations
correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c1809f2c-8309-42c6-9d20-24ec26e9b974
📒 Files selected for processing (2)
crates/lakekeeper-bin/src/wait_for_db.rscrates/lakekeeper-storage-postgres/src/migrations/mod.rs
✅ PR Title Formatted CorrectlyThe title of this PR match the correct format. Thank you! |
Guard against running an older binary against a database that a newer Lakekeeper has already migrated.
check_migration_status only checked one direction (are the binary's migrations applied?), so an older binary — whose migrations are a subset of what's applied — reported Complete and served against the newer schema. That risks runtime errors or silent data corruption when the binary writes against schema invariants it doesn't know about.
Add MigrationState::Ahead: any applied migration whose version this binary's migrator does not contain means the DB is newer. The serve gate (wait_for_db) now fails fast on Ahead instead of retrying — waiting never resolves a newer DB. Run
serve --force-startto start anyway (emergency rollback, accepting the risk of schema incompatibility).The migrate command already aborted on this via VersionMissing; this brings serve in line.
Summary by CodeRabbit
Release Notes