Skip to content

Fix nested D1 migration loading in vitest pool - #14870

Draft
cyphercodes wants to merge 1 commit into
cloudflare:mainfrom
cyphercodes:cyphercodes/fix-nested-d1-migrations-14866
Draft

Fix nested D1 migration loading in vitest pool#14870
cyphercodes wants to merge 1 commit into
cloudflare:mainfrom
cyphercodes:cyphercodes/fix-nested-d1-migrations-14866

Conversation

@cyphercodes

@cyphercodes cyphercodes commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #14866.

Read D1 migration files recursively so readD1Migrations() supports the nested layout that migrations_pattern can match, such as 0001_init/migration.sql. The returned migration names preserve forward-slash relative paths and are sorted by migration prefix.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows: N/A
    • Additional testing not necessary because: N/A
  • Public documentation
    • Documentation not necessary because: this fixes runtime/test helper behavior without changing public docs

Note

This is a contribution from an AI agent: Hermes Agent, gpt-5.5.

Validation:

  • pnpm --filter @cloudflare/vitest-pool-workers test d1.test.ts
  • pnpm --filter @cloudflare/vitest-pool-workers check:type
  • pnpm --filter @cloudflare/vitest-pool-workers build
  • oxfmt --check packages/vitest-pool-workers/src/pool/d1.ts packages/vitest-pool-workers/test/d1.test.ts .changeset/read-nested-d1-migrations.md
  • git diff --check

Open in Devin Review

@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f50d753

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/vitest-pool-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@workers-devprod
workers-devprod requested review from a team and edmundhung and removed request for a team July 27, 2026 03:55
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/read-nested-d1-migrations.md: [@cloudflare/wrangler]
  • packages/vitest-pool-workers/src/pool/d1.ts: [@cloudflare/wrangler]
  • packages/vitest-pool-workers/test/d1.test.ts: [@cloudflare/wrangler]

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@edmundhung

Copy link
Copy Markdown
Member

Thanks for working on this, @cyphercodes. The nested migration case definitely needs fixing.

I think the current recursive scan could be confusing as it may not match migrations_pattern exactly and could include SQL files that Wrangler would otherwise ignore.

How about supporting an explicit options form?

// Keep the current API signature for backward compatibility
readD1Migrations(migrationsDir: string);
// New: Accept an option that allow you to specify how it should discover the migrations files similar to the config
readD1Migrations({
  projectPath, // Optional: defaults to process.cwd()
  migrationsDir,
  migrationsPattern,
});

It would also be great if you could extract the existing discovery logic into @cloudflare/workers-utils so it could be reused by both Wrangler and Vitest Pool Workers:

type D1MigrationFile = {
  name: string;
  filePath: string;
};

function getD1MigrationFiles(
  options: {
    projectPath: string;
    migrationsDir?: string;
    migrationsPattern?: string;
  }
): D1MigrationFile[];

Would you be open to implementing it along those lines? It's a slightly broader change, but it would help us keeping both code paths consistent and make this easier to maintain long term.

@edmundhung
edmundhung marked this pull request as draft July 29, 2026 09:19
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.

[vitest-pool-workers] readD1Migrations() does not read the nested migration layout that migrations_pattern supports

3 participants