Skip to content

test(migrate): use timestamp cutoff in filterDbmateEra - #1273

Merged
kalbasit merged 2 commits into
mainfrom
user/wnasreddine/fix-migrate-test-filter
May 25, 2026
Merged

kalbasit merged 2 commits into
mainfrom
user/wnasreddine/fix-migrate-test-filter

Conversation

@kalbasit

Copy link
Copy Markdown
Owner

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.

@kalbasit

kalbasit commented May 25, 2026 •

Copy link
Copy Markdown
Owner Author

@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label May 25, 2026
@kalbasit kalbasit mentioned this pull request May 25, 2026
7 tasks done
@dosubot dosubot Bot added the go Pull requests that update go code label May 25, 2026
@coderabbitai

coderabbitai Bot commented May 25, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9fec94c1-69a3-4404-b51d-5fad3bd08686

📥 Commits

Reviewing files that changed from the base of the PR and between c76e0b5 and 8101033.

📒 Files selected for processing (1)
  • pkg/database/migrate/migrate_test.go

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Improved test seeding to more reliably exclude migrations from after the bridge era by parsing the leading 14‑digit numeric prefix of migration names and filtering any with version >= 20260520000000; migration names that are shorter or non-numeric in that prefix are left unchanged so they continue to be included in test runs.

Walkthrough

Test 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.

Changes

Migration bridge-era filtering

Layer / File(s) Summary
Bridge era timestamp-based filtering
pkg/database/migrate/migrate_test.go
Adds bridgeEraStart (20260520000000) and refactors filterDbmateEra to parse the first 14 characters of migration base filenames as digits, excluding migrations with parsed version >= cutoff; bases shorter than 14 chars or with non-digit prefixes are kept.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nibble filenames by dawn's first light,
Counting fourteen digits, snug and bright,
If the number crosses the bridge I pause,
Otherwise I keep them — such are my laws,
Hopping through tests till morning's sight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: switching filterDbmateEra to use a timestamp-based cutoff instead of name patterns.
Description check ✅ Passed The description clearly explains the problem (name-pattern filtering breaks with new migrations), the solution (timestamp-based cutoff), and the rationale (scalable, matches existing approach).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/database/migrate/migrate_test.go Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 754fc3a and 055ea0f.

📒 Files selected for processing (1)
  • pkg/database/migrate/migrate_test.go

Comment thread pkg/database/migrate/migrate_test.go Resolved
@kalbasit
kalbasit changed the base branch from main to user/wnasreddine/fix-purge-nar-race May 25, 2026 20:28
@kalbasit
kalbasit force-pushed the user/wnasreddine/fix-migrate-test-filter branch from 055ea0f to c76e0b5 Compare May 25, 2026 20:28

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
pkg/database/migrate/migrate_test.go (1)

533-558: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use 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 *.sql filename as an int64 timestamp 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

📥 Commits

Reviewing files that changed from the base of the PR and between 055ea0f and c76e0b5.

📒 Files selected for processing (1)
  • pkg/database/migrate/migrate_test.go

@codecov

codecov Bot commented May 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (user/wnasreddine/fix-purge-nar-race@3b59990). Learn more about missing BASE report.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from user/wnasreddine/fix-purge-nar-race to main May 25, 2026 21:15
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels May 25, 2026
kalbasit added 2 commits May 25, 2026 21:15
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
@kalbasit
kalbasit force-pushed the user/wnasreddine/fix-migrate-test-filter branch from c76e0b5 to 8101033 Compare May 25, 2026 21:15
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels May 25, 2026
@kalbasit
kalbasit enabled auto-merge (squash) May 25, 2026 21:16
@kalbasit
kalbasit merged commit d7780d8 into main May 25, 2026
21 checks passed
@kalbasit
kalbasit deleted the user/wnasreddine/fix-migrate-test-filter branch May 25, 2026 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

go Pull requests that update go code merge-stack size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant