Fix nested D1 migration loading in vitest pool - #14870
Conversation
🦋 Changeset detectedLatest commit: f50d753 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
|
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 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 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. |
Fixes #14866.
Read D1 migration files recursively so
readD1Migrations()supports the nested layout thatmigrations_patterncan match, such as0001_init/migration.sql. The returned migration names preserve forward-slash relative paths and are sorted by migration prefix.Note
This is a contribution from an AI agent: Hermes Agent, gpt-5.5.
Validation:
pnpm --filter @cloudflare/vitest-pool-workers test d1.test.tspnpm --filter @cloudflare/vitest-pool-workers check:typepnpm --filter @cloudflare/vitest-pool-workers buildoxfmt --check packages/vitest-pool-workers/src/pool/d1.ts packages/vitest-pool-workers/test/d1.test.ts .changeset/read-nested-d1-migrations.mdgit diff --check