Skip to content

fix: match migration finding with netlify/build#8191

Merged
pieh merged 5 commits intomainfrom
fix/match-migration-finding-with-netlify-build
Apr 22, 2026
Merged

fix: match migration finding with netlify/build#8191
pieh merged 5 commits intomainfrom
fix/match-migration-finding-with-netlify-build

Conversation

@pieh
Copy link
Copy Markdown
Contributor

@pieh pieh commented Apr 22, 2026

🎉 Thanks for submitting a pull request! 🎉

Summary

This updates logic of finding migration files with how https://github.com/netlify/build/blob/main/packages/build/src/plugins_core/db_setup/migrations.ts behaves

It:

  • checks if migration directory has migration.sql file
  • check migration name pattern before recognizing it as actual migration
  • handles "flat" .sql files (that are not nested in directory)

It does NOT point out validation errors - https://github.com/netlify/build/blob/main/packages/build/src/plugins_core/db_setup/validation.ts

This probably should be done as follow up (or maybe block this change to have it included)


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 22, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Updated migration discovery to use stricter pattern matching for local database migrations, ensuring only properly formatted migrations are recognized.
    • Refined version parsing to require underscore separators, affecting which migration files are included in status checks.
  • Tests

    • Enhanced test suite with improved filesystem mocking for more realistic migration discovery validation.

Walkthrough

The changes refine migration discovery logic in readLocalMigrations to use a stricter MIGRATION_NAME_PATTERN and a two-pass approach: first collecting valid migration names from directories containing migration.sql files and standalone .sql files (with extension stripped), then parsing versions from collected names. The parseVersion function is tightened to only accept numeric prefixes followed by underscores. The test suite is refactored to use an in-memory mock filesystem (mockFS) replacing the previous directory-only approach, with new tests verifying migration inclusion/exclusion rules based on migration.sql presence and filename patterns.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 concisely summarizes the main change: aligning migration finding logic with netlify/build behavior, which matches the core modifications to db-status.ts.
Description check ✅ Passed The description clearly explains the motivation, implementation details, and scope of changes, directly relating to the pull request's objective of matching netlify/build migration discovery behavior.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/match-migration-finding-with-netlify-build

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.

❤️ Share

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

📊 Benchmark results

Comparing with cb924d4

  • Dependency count: 1,061 (no change)
  • Package size: 355 MB (no change)
  • Number of ts-expect-error directives: 356 (no change)

eduardoboucas
eduardoboucas previously approved these changes Apr 22, 2026
@pieh pieh marked this pull request as ready for review April 22, 2026 20:37
@pieh pieh requested a review from a team as a code owner April 22, 2026 20:37
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/commands/database/db-status.ts (1)

76-97: Remove comments that restate the control flow.

These comments describe the adjacent loop/setup without adding extra intent; the variable names already make the two phases clear. As per coding guidelines, **/*.{ts,tsx,js,jsx}: Never write comments on what the code does; make the code clean and self-explanatory instead.

Proposed cleanup
-  // First pass is to extract migration names
   const migrationNames: string[] = []
@@
-  // Second pass to parse version and create migration entries
   const migrations: MigrationEntry[] = []
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/commands/database/db-status.ts` around lines 76 - 97, Remove the
redundant explanatory comments around the two-pass migration discovery logic:
delete the comments "// First pass is to extract migration names" and "// Second
pass to parse version and create migration entries" (the code using entries,
migrationNames, MIGRATION_NAME_PATTERN, fileExistsAsync, join and the
migrations: MigrationEntry[] declaration is already self-descriptive). Keep the
loops and variable names intact; no functional changes, just remove those two
comments so the code adheres to the guideline of avoiding comments that restate
control flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/commands/database/db-status.ts`:
- Around line 76-97: Remove the redundant explanatory comments around the
two-pass migration discovery logic: delete the comments "// First pass is to
extract migration names" and "// Second pass to parse version and create
migration entries" (the code using entries, migrationNames,
MIGRATION_NAME_PATTERN, fileExistsAsync, join and the migrations:
MigrationEntry[] declaration is already self-descriptive). Keep the loops and
variable names intact; no functional changes, just remove those two comments so
the code adheres to the guideline of avoiding comments that restate control
flow.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 16dc2a69-964a-434f-98d4-aa9991808417

📥 Commits

Reviewing files that changed from the base of the PR and between cb924d4 and 58ff715.

📒 Files selected for processing (2)
  • src/commands/database/db-status.ts
  • tests/unit/commands/database/db-status.test.ts

@pieh pieh merged commit e2e8267 into main Apr 22, 2026
69 checks passed
@pieh pieh deleted the fix/match-migration-finding-with-netlify-build branch April 22, 2026 20:48
eduardoboucas pushed a commit that referenced this pull request Apr 22, 2026
🤖 I have created a release *beep* *boop*
---


## [25.3.0](v25.2.0...v25.3.0)
(2026-04-22)


### Features

* add deprecation messaging for legacy Netlify DB extension
([#8141](#8141))
([cb924d4](cb924d4))


### Bug Fixes

* match migration finding with netlify/build
([#8191](#8191))
([e2e8267](e2e8267))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: token-generator-app[bot] <82042599+token-generator-app[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants