Skip to content

fix(dev): accept a D1 preview_database_id and use it locally - #1039

Open
konaito wants to merge 1 commit into
voidzero-dev:mainfrom
konaito:fix/d1-preview-database-id
Open

konaito wants to merge 1 commit into
voidzero-dev:mainfrom
konaito:fix/d1-preview-database-id

Conversation

@konaito

@konaito konaito commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #1038

Summary

  • cf-config-migrate.ts: drop preview_database_id from D1 bindings (top level and environments) before the cf converter runs. The converter no longer reports a blocking follow-up, and the deployable config keeps database_id.
  • plugin-cloudflare-config.ts: add applyLocalD1PreviewIds(). During serve, it sets each D1 binding's local ID to its preview_database_id, the same database that void db commands and the dev migration plugin already use (local-d1.ts).
  • plugin-cloudflare.ts: with CLOUDFLARE_ENV, the settings are translated once before the merge, which drops the preview ID. The selected environment and the original settings are kept so the dev server still sees it. The first settings that declare a binding decide its local ID.
  • config.ts: add preview_database_id to the D1 binding type.

This is separate from #1037 (a D1 binding without database_id), though both touch the serve branch of plugin-cloudflare.ts.

Tests

  • cf-config-migrate.test.ts: a D1 binding with a preview ID, top level and in a named environment, deploys under database_id. Both cases failed before the fix with cf cannot migrate Cloudflare setting d1_databases.0.
  • plugin-cloudflare-config.test.ts: applyLocalD1PreviewIds() sets the preview ID, leaves bindings without one alone, and lets an environment's declaration take precedence.

Manual check with a playground app (void db migrate, then a row inserted into the preview database):

  • Before: vp dev and vp build exit with the error in the issue.
  • After: vp dev, with and without CLOUDFLARE_ENV, returns the row from /api/users. Only the preview ID's sqlite file exists under .void/v3/d1.
  • With the serve ID swap removed, the dev Worker opened the database_id database, which had no tables, and /api/users returned 500.
  • vp build writes the Worker's DB binding with database_id.

Checks

  • vp check: pass
  • vp run check:types: pass
  • vp run --cache build:all: pass
  • vp test run --project unit --project unit-pglite --project cli-unit: 11790 passed, 18 failed. 16 in init.test.ts and 1 in nitro.test.ts fail the same way on main in my environment. 1 in wrapper.test.ts timed out at 5000 ms in the full run and passes on its own.

cloudflare-do-safety: ran the Durable Object/D1 cost-pattern scan on this diff; no matches in the added lines (the only match in the changed files is an existing regex loop at packages/void/src/config.ts:287, unrelated to DO/D1).

A D1 binding with preview_database_id stopped the dev server and builds
with "cf cannot migrate Cloudflare setting d1_databases.0". The cf
converter reports the option as unsupported, and Void did not handle it.

Deployments keep using database_id. The dev server now binds the preview
ID, which local void db commands already use, so migrations and the app
read the same local database.

This branch has not been deployed

No deployments
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.

D1 preview_database_id stops vp dev and vp build with "cf cannot migrate"

1 participant