fix: fix panic in migrator.upByOne when already migrated by a newer version#564
Conversation
WalkthroughA guard condition in the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #564 +/- ##
==========================================
- Coverage 28.75% 28.71% -0.05%
==========================================
Files 175 175
Lines 7062 7059 -3
==========================================
- Hits 2031 2027 -4
Misses 4913 4913
- Partials 118 119 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
migrations/migrator.go (1)
247-247: Consider aligningIsUpToDatewith the new guard logic.For consistency with the fix in
upByOne, this condition could be changed toversion >= len(m.migrations). Currently, iflastVersion > len(m.migrations)(newer version already migrated), this returnsfalsewhich is semantically misleading, though safe sinceupByOnenow handles it gracefully.♻️ Optional: Align semantic consistency
- return version == len(m.migrations), nil + return version >= len(m.migrations), nil🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@migrations/migrator.go` at line 247, The IsUpToDate check currently returns version == len(m.migrations) which misreports cases where lastVersion > len(m.migrations); update the condition in IsUpToDate to use version >= len(m.migrations) so it returns true when the recorded version is at or beyond the number of migrations (aligning semantics with the guard added to upByOne), referencing the IsUpToDate function, the version/lastVersion variables and m.migrations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@migrations/migrator.go`:
- Line 247: The IsUpToDate check currently returns version == len(m.migrations)
which misreports cases where lastVersion > len(m.migrations); update the
condition in IsUpToDate to use version >= len(m.migrations) so it returns true
when the recorded version is at or beyond the number of migrations (aligning
semantics with the guard added to upByOne), referencing the IsUpToDate function,
the version/lastVersion variables and m.migrations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 6ac6ce1d-c3fc-4d08-a487-4f75e3bb37c9
📒 Files selected for processing (1)
migrations/migrator.go
Rolling upgrade timing/restart issues can cause a pod from an older version to start after a newer one has finished its migrations, leading to an out of bounds panic here.
Instead return
AlreadyUpToDatewhen encountering newer versions