Skip to content

[wrangler] Fix nested D1 migrations#13913

Open
swalker326 wants to merge 9 commits into
cloudflare:mainfrom
swalker326:d1-recursive-migrations-13257
Open

[wrangler] Fix nested D1 migrations#13913
swalker326 wants to merge 9 commits into
cloudflare:mainfrom
swalker326:d1-recursive-migrations-13257

Conversation

@swalker326
Copy link
Copy Markdown

@swalker326 swalker326 commented May 13, 2026

Fixes #13257.

Fix D1 migration discovery so wrangler d1 migrations list and wrangler d1 migrations apply recursively include nested .sql files under migrations_dir. Nested migrations are recorded using relative paths, and wrangler d1 migrations create now accounts for nested numeric prefixes when choosing the next migration number.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: this fixes existing Wrangler D1 migration behavior without changing public command usage.

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

30D310E7-7F82-47F2-8C87-86AB5CE8C22D_1_105_c
Open in Devin Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 13, 2026

🦋 Changeset detected

Latest commit: 873f35c

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

This PR includes changesets to release 3 packages
Name Type
wrangler Patch
@cloudflare/vite-plugin Patch
@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 NuroDev and removed request for a team May 13, 2026 15:39
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented May 13, 2026

Codeowners approval required for this PR:

  • @cloudflare/d1
  • ✅ @cloudflare/wrangler
Show detailed file reviewers
  • packages/wrangler/src/tests/d1/migrate.test.ts: [@cloudflare/d1]
  • packages/wrangler/src/tests/d1/migrations/helpers.test.ts: [@cloudflare/d1]
  • packages/wrangler/src/d1/execute.ts: [@cloudflare/d1]
  • packages/wrangler/src/d1/migrations/apply.ts: [@cloudflare/d1]
  • packages/wrangler/src/d1/migrations/helpers.ts: [@cloudflare/d1]

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

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 6 additional findings.

Open in Devin Review

Copy link
Copy Markdown
Member

@NuroDev NuroDev left a comment

Choose a reason for hiding this comment

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

Great little fix. Thank you @swalker326!

@NuroDev NuroDev enabled auto-merge (squash) May 14, 2026 10:08
@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk May 14, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 14, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13913

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13913

miniflare

npm i https://pkg.pr.new/miniflare@13913

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13913

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13913

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13913

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13913

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13913

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@13913

wrangler

npm i https://pkg.pr.new/wrangler@13913

commit: 873f35c

Comment thread packages/wrangler/src/__tests__/d1/migrate.test.ts
@alsuren alsuren mentioned this pull request May 14, 2026
5 tasks
@k0d13
Copy link
Copy Markdown

k0d13 commented May 14, 2026

A little concerned that this may break existing flows
I use drizzle and just have a script that copies the drizzle//migration.sql, modifies it, and writes it to drizzle/.sql
If nested support alone is added, how will it handle both the old drizzle/.sql and the "new" drizzle//migration.sql?

@swalker326
Copy link
Copy Markdown
Author

A little concerned that this may break existing flows I use drizzle and just have a script that copies the drizzle//migration.sql, modifies it, and writes it to drizzle/.sql If nested support alone is added, how will it handle both the old drizzle/.sql and the "new" drizzle//migration.sql?

Nested directories are not required, they're just supported with this PR. You can put top level *.sql files OR folders with *.sql files in them. For your setup you would see no change, continue to copy the sql files over.

auto-merge was automatically disabled May 15, 2026 22:53

Head branch was pushed to by a user without write access

@swalker326 swalker326 closed this May 16, 2026
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in workers-sdk May 16, 2026
@swalker326 swalker326 reopened this May 16, 2026
@github-project-automation github-project-automation Bot moved this from Done to Untriaged in workers-sdk May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

D1 migrations_dir | Support recursive .sql file search

6 participants