Repository navigation
test(migrate): use timestamp cutoff in filterDbmateEra - #1273
Conversation
|
This change is part of the following stack: Change managed by git-spice. |
|
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)
📝 WalkthroughSummary by CodeRabbit
WalkthroughTest migration seeding now filters dbmate-era files by parsing a 14-digit numeric prefix and excluding any migration whose parsed version is >= bridgeEraStart (20260520000000); filenames shorter than 14 chars or with non-digit prefixes are included unchanged. ChangesMigration bridge-era filtering
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Code Review
This pull request updates the filterDbmateEra function in pkg/database/migrate/migrate_test.go to filter migrations by parsing the 14-digit timestamp prefix of the filename instead of matching specific string patterns. Feedback on this change highlights that the manual parsing logic is fragile if filenames are shorter than 14 characters or contain non-digit characters, and suggests a safer parsing implementation.
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 `@pkg/database/migrate/migrate_test.go`:
- Around line 533-537: The loop building v from base accepts non-digits and
short prefixes; change it to require exactly 14 digits: first check that
len(base) >= 14, validate each of the 14 characters base[0:14] is between '0'
and '9', and only then parse those 14 characters into v (fail the test
immediately with a clear error if not); update any call site that relied on
permissive parsing to either supply valid 14-digit versions or handle the test
failure accordingly.
🪄 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: b1245e11-6951-44c8-b8b1-ad73f117cef7
📒 Files selected for processing (1)
pkg/database/migrate/migrate_test.go
055ea0f to
c76e0b5
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
pkg/database/migrate/migrate_test.go (1)
533-558:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUse strict 14-digit parsing to match production contract.
The current implementation silently includes migration files with malformed version prefixes (< 14 characters or non-digit characters), while production code in
listEmbeddedVersions(fresh.go:148-187) strictly requires exactly 14 leading digits and returns an error otherwise. This mismatch means tests could pass with invalid migration filenames that would fail at runtime.Change the parsing to match the production validation contract: require exactly 14 digits, parse using
strconv.ParseInt, and fail the test immediately on malformed input.Proposed fix to align with production validation
+import "strconv" ... -func filterDbmateEra(files []string) []string { +func filterDbmateEra(t *testing.T, files []string) []string { + t.Helper() out := make([]string, 0, len(files)) for _, f := range files { base := f if idx := strings.LastIndex(base, "/"); idx >= 0 { base = base[idx+1:] } - // Require exactly 14 leading digits; anything else can't be a - // migration version and is included unchanged. - if len(base) < 14 { - out = append(out, f) - - continue - } - - var v int64 - - valid := true - - for i := range 14 { - c := base[i] - if c < '0' || c > '9' { - valid = false - - break - } - - v = v*10 + int64(c-'0') - } - - if !valid || v < bridgeEraStart { + require.GreaterOrEqualf(t, len(base), 14, "migration filename too short: %q", f) + v, err := strconv.ParseInt(base[:14], 10, 64) + require.NoErrorf(t, err, "invalid migration version prefix in %q", f) + + if v < bridgeEraStart { out = append(out, f) } } return out }Update the call site:
- pre := filterDbmateEra(all) + pre := filterDbmateEra(t, all)As per coding guidelines, context snippet 1 shows that production migration versioning parses the first 14 chars of each embedded
*.sqlfilename as anint64timestamp prefix (strconv.ParseInt(base[:14], 10, 64)), so the test's 14-digit prefix parsing filter must align with this contract for version cutoff decisions to be meaningful.🤖 Prompt for 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. In `@pkg/database/migrate/migrate_test.go` around lines 533 - 558, Replace the current ad-hoc 14-char loop in migrate_test.go with strict 14-digit parsing to match production: require len(base) >= 14, call strconv.ParseInt(base[:14], 10, 64) to parse the version, and if ParseInt returns an error (malformed prefix) fail the test immediately (t.Fatalf) instead of appending the file unchanged; then use the parsed v and existing bridgeEraStart comparison to decide whether to include f in out. Refer to symbols base, out, f, bridgeEraStart and the production validator listEmbeddedVersions for alignment.
🤖 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.
Duplicate comments:
In `@pkg/database/migrate/migrate_test.go`:
- Around line 533-558: Replace the current ad-hoc 14-char loop in
migrate_test.go with strict 14-digit parsing to match production: require
len(base) >= 14, call strconv.ParseInt(base[:14], 10, 64) to parse the version,
and if ParseInt returns an error (malformed prefix) fail the test immediately
(t.Fatalf) instead of appending the file unchanged; then use the parsed v and
existing bridgeEraStart comparison to decide whether to include f in out. Refer
to symbols base, out, f, bridgeEraStart and the production validator
listEmbeddedVersions for alignment.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b49a6c3b-ed7a-43b8-a2d6-cfbbd6f26d1a
📒 Files selected for processing (1)
pkg/database/migrate/migrate_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## user/wnasreddine/fix-purge-nar-race #1273 +/- ##
=====================================================================
Coverage ? 0
=====================================================================
Files ? 0
Lines ? 0
Branches ? 0
=====================================================================
Hits ? 0
Misses ? 0
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The previous implementation filtered bridge-era migrations by name
pattern ("ent_baseline", "serial_to_identity"). Adding any new
post-bridge migration caused the dbmate-era seed test to break with
a "missing out-of-order migration" error from goose.
Switch to a timestamp-based cutoff (bridgeEraStart = 20260520000000).
Any migration with a version >= that constant is post-bridge and is
excluded from the dbmate-era seed, regardless of its name. This
matches the existing fileVersions() parsing approach and will
correctly exclude all future incremental migrations without requiring
a name-list update.
The previous loop accepted non-digit characters and short filenames, which could produce garbage version values and incorrectly filter (or not filter) migrations. Add explicit guards: skip any file whose name is shorter than 14 characters (included in the pre-bridge output), then validate that each of the 14 prefix characters is an ASCII digit before building the version integer. Files that fail validation are passed through unchanged. Addresses: PRRT_kwDONV6tZs6EnfW-, PRRT_kwDONV6tZs6EngZi
c76e0b5 to
8101033
Compare
The previous implementation filtered bridge-era migrations by name
pattern ("ent_baseline", "serial_to_identity"). Adding any new
post-bridge migration caused the dbmate-era seed test to break with
a "missing out-of-order migration" error from goose.
Switch to a timestamp-based cutoff (bridgeEraStart = 20260520000000).
Any migration with a version >= that constant is post-bridge and is
excluded from the dbmate-era seed, regardless of its name. This
matches the existing fileVersions() parsing approach and will
correctly exclude all future incremental migrations without requiring
a name-list update.