fix(migrations): use numeric ordering to allow 3-digit migrations#198
fix(migrations): use numeric ordering to allow 3-digit migrations#198Lutherwaves wants to merge 1 commit into
Conversation
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughMigration execution now orders by parsed numeric ID rather than lexical filename sort. Helper functions extract numeric prefixes and sort deterministically by id with lexical tie-break. Integration into ChangesNumeric-aware migration ordering
🎯 2 (Simple) | ⏱️ ~15 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ 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 |
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 `@storage/migration_internal_test.go`:
- Around line 116-123: The helper function slicesIndex is redundant—replace all
calls to slicesIndex(s, v) with slices.Index(s, v) from the standard library and
add the "slices" import; then remove the slicesIndex function entirely. Locate
usages in tests (any references to slicesIndex) and update them to slices.Index,
update the import block to include "slices", and delete the slicesIndex helper
function to avoid duplicate boilerplate.
🪄 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: ASSERTIVE
Plan: Pro Plus
Run ID: d48fbc4b-56b1-451d-9a47-870f7e281670
📒 Files selected for processing (2)
storage/migration.gostorage/migration_internal_test.go
946e881 to
1faea2d
Compare
The runner derived each migration id from the numeric filename prefix and
gated application on a numeric high-water mark, but chose run order with
sort.Strings — a lexical sort. The two agree only while every id is the same
width. The first 3-digit migration ("100__") sorts before "10__".."99__"
lexically, so on a fresh database the runner applies 100/101 first, advances
the numeric mark past 99, then silently skips migrations 10..99. Incrementally
migrated databases (mark already >= 99) are unaffected, so this only bites
fresh environments: new dev setups, CI, ephemeral test databases.
Sort by the parsed numeric id — the same value the apply gate uses — with a
lexical tie-break, so run order and gate stay consistent regardless of digit
count and zero-padding is no longer load-bearing. Extract migrationID as the
shared parse helper used by both paths.
Fixes #197
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1faea2d to
f6eff91
Compare
Closes #197.
Problem
Migration files are named
<id>__<description>.yaml. The runner derives each migration id by parsing the numeric prefix and gates application on a numeric high-water mark (apply whenid > mark). But it chose run order withsort.Strings(keys)— a lexical sort.Lexical and numeric order agree only while every id has the same digit width. The first 3-digit migration (
100__…) sorts before10__…..99__…lexically (the char after100is_> any digit). So on a fresh database (mark = 0) the runner:01..09(mark → 9),100,101next in lexical order (mark → 101),10..99, whose ids are now below the mark, and silently skips all of them — no error, recorded as success.Incrementally migrated databases (mark already ≥ 99) are unaffected, so this only bites fresh environments: new dev setups, CI, ephemeral test databases.
Fix
Order keys by their parsed numeric id — the same value the apply gate uses — with a lexical tie-break for equal ids and a lexical fallback for unparseable prefixes (so ordering stays deterministic; a bad id is still surfaced by the existing per-migration check).
migrationIDis extracted as the single parse helper shared by both the ordering and the gate, so they can no longer disagree.Tests
storage/migration_internal_test.go:TestSortMigrationKeysOrdersNumericallyNotLexically— mixed 1/2/3-digit ids incl. a tie on100; asserts1,2,9,10,99,100,100order (would fail undersort.Strings).TestSortMigrationKeysFallsBackToLexicalForUnparseablePrefix— non-numeric prefixes sort deterministically without panicking.go build ./...,go vet ./storage/, andgo test ./storage/all pass.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests