Skip to content

[wrangler] Include column names in D1 SQL export#12277

Merged
petebacondarwin merged 4 commits into
mainfrom
fix/7507-d1-export-column-names
May 21, 2026
Merged

[wrangler] Include column names in D1 SQL export#12277
petebacondarwin merged 4 commits into
mainfrom
fix/7507-d1-export-column-names

Conversation

@penalosa

@penalosa penalosa commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #7507.

D1 SQL exports now include column names in INSERT statements. Previously, exports generated:

INSERT INTO "users" VALUES(1,'John','john@example.com');

Now exports generate:

INSERT INTO "users" ("id","name","email") VALUES(1,'John','john@example.com');

This ensures that exported SQL can be successfully imported even when the target table has columns in a different order than the original, which commonly occurs during iterative development when schemas evolve.


  • 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 is a bug fix with no user-facing API changes

Open with Devin

@changeset-bot

changeset-bot Bot commented Jan 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a2be02c

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

@claude

claude Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Claude finished @penalosa's task —— View job


Changeset Review

Todo List

  • Read changeset guidelines
  • Read changeset file
  • Validate changeset against criteria
  • Post review results

✅ All changesets look good

The changeset at .changeset/include-column-names-d1-export.md passes validation:

  • Version Type: ✅ patch - Appropriate for a bug fix that improves SQL export behavior
  • Changelog Quality: ✅ Clear title and detailed body explaining the change and its benefit
  • Markdown Headers: ✅ No h1/h2/h3 headers used
  • Analytics: ✅ No analytics changes in this PR
  • Experimental Features: ✅ Not applicable - this is a fix to stable functionality

@pkg-pr-new

pkg-pr-new Bot commented Jan 29, 2026

Copy link
Copy Markdown
create-cloudflare

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

@cloudflare/kv-asset-handler

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

miniflare

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

@cloudflare/pages-shared

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

@cloudflare/unenv-preset

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

@cloudflare/vite-plugin

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

@cloudflare/vitest-pool-workers

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

@cloudflare/workers-editor-shared

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

@cloudflare/workers-utils

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

wrangler

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

commit: a2be02c

@penalosa

Copy link
Copy Markdown
Contributor Author

@claude this seems to be failing tests. Can you analyse and fix?

@penalosa penalosa added the product:d1 Relating to Cloudflare D1: https://developers.cloudflare.com/d1/ label Jan 29, 2026
@claude

claude Bot commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Claude finished @penalosa's task —— View job


✅ Tests Fixed Successfully!

Todo List

  • Install dependencies
  • Run tests to identify failures
  • Analyze failing tests and code changes
  • Fix test failures
  • Verify fixes work
  • Run linting/formatting checks
  • Commit and push fixes

Issue Identified and Fixed

The tests were failing because they expected the old INSERT format without column names:

INSERT INTO "foo" VALUES(1,'xxx');

But after your changes to include column names in D1 SQL exports, the code now generates:

INSERT INTO "foo" ("id","value") VALUES(1,'xxx');

Changes Made

Updated test expectations in /packages/wrangler/src/__tests__/d1/export.test.ts:

  • Fixed INSERT statement expectations for both foo and bar tables
  • Added column names ("id","value") to all INSERT statements in the test assertions

The fix has been committed and pushed to the PR branch. The tests should now pass with the new column name format.


@penalosa penalosa marked this pull request as ready for review January 29, 2026 18:28
@penalosa penalosa requested review from a team as code owners January 29, 2026 18:28

@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 3 additional flags.

Open in Devin Review

Comment thread packages/miniflare/src/workers/d1/dumpSql.ts

@vicb vicb 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.

LGTM, one nit

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Jan 29, 2026

@alsuren alsuren 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.

I think I agree with this. We are diverging from the sqlite .dump command, and making the output more verbose, but it should make things more robust (sqlite column ordering is notoriously fragile).

@penalosa Let's hold off on merging this until we're ready to merge the internal copy of it as well, just in case there is anything we've not thought of (I tagged you in my gitlab MR for this).

@dario-piotrowicz dario-piotrowicz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This needs to wait until the internal PR has landed

@github-project-automation github-project-automation Bot moved this from Approved to In Review in workers-sdk Feb 2, 2026
@petebacondarwin petebacondarwin marked this pull request as draft February 2, 2026 21:09
@petebacondarwin petebacondarwin added blocked Blocked on other work internal Requires support from the Cloudflare Platform labels Feb 2, 2026
@alsuren

alsuren commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

I just pushed a tweak to make it match what we're planning to ship in our next release (we checked the stats already and don't expect to break any databases that aren't already broken).

@alsuren alsuren force-pushed the fix/7507-d1-export-column-names branch from 1d145a7 to 609e2fc Compare February 27, 2026 11:38
@penalosa penalosa force-pushed the fix/7507-d1-export-column-names branch from 609e2fc to dd50c1f Compare April 17, 2026 12:53
@penalosa penalosa marked this pull request as ready for review April 17, 2026 12:53
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/d1
  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@workers-devprod workers-devprod 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.

Codeowners reviews satisfied

@github-actions

github-actions Bot commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

✅ All changesets look good

devin-ai-integration[bot]

This comment was marked as resolved.

@alsuren

alsuren commented May 21, 2026

Copy link
Copy Markdown
Contributor

This needs to wait until the internal PR has landed

@dario-piotrowicz this has been out in prod for a few months with no problems.

@alsuren alsuren requested a review from dario-piotrowicz May 21, 2026 10:37
penalosa and others added 3 commits May 21, 2026 14:31
…T statements

The dumpSql function now includes column names in INSERT statements.
Updated test expectations to match the new format:
- INSERT INTO "table" VALUES(...) → INSERT INTO "table" ("col1","col2") VALUES(...)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Somhairle MacLeòid <penalosa@users.noreply.github.com>
Add stats tracking for INSERT statement sizes to help analyze the impact
of including column names in D1 SQL exports. This syncs the miniflare
dumpSql.ts with the d1-worker version from GitLab MR 1056.
@petebacondarwin petebacondarwin force-pushed the fix/7507-d1-export-column-names branch from dd50c1f to 51c853c Compare May 21, 2026 13:48
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/d1
  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@petebacondarwin petebacondarwin removed blocked Blocked on other work internal Requires support from the Cloudflare Platform labels May 21, 2026
@petebacondarwin petebacondarwin force-pushed the fix/7507-d1-export-column-names branch from af61e9b to a2be02c Compare May 21, 2026 14:22
@petebacondarwin petebacondarwin dismissed dario-piotrowicz’s stale review May 21, 2026 14:22

PR is unblocked and ready for review

@petebacondarwin petebacondarwin enabled auto-merge (squash) May 21, 2026 14:36
@petebacondarwin petebacondarwin merged commit 8c569c6 into main May 21, 2026
54 checks passed
@petebacondarwin petebacondarwin deleted the fix/7507-d1-export-column-names branch May 21, 2026 14:37
@github-project-automation github-project-automation Bot moved this from In Review to Done in workers-sdk May 21, 2026
penalosa added a commit that referenced this pull request May 28, 2026
Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Somhairle MacLeòid <penalosa@users.noreply.github.com>
Co-authored-by: David Laban <dlaban@cloudflare.com>
Co-authored-by: Pete Bacon Darwin <pbacondarwin@cloudflare.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:d1 Relating to Cloudflare D1: https://developers.cloudflare.com/d1/

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

🐛 BUG: Exported SQL Fails to Import Due to Missing Column Names in INSERT Statements

6 participants