Skip redundant Cloudflare D1 schema preparation#1455
Open
jadch wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
createD1ExecutorDb()is used by both the edge Worker app and each MCP session Durable Object. It currently replays the full idempotent runtime-schema ensure on every open, even after the database is current.With the current schema, a second open emits 46
CREATE TABLE/CREATE INDEX/ALTER TABLEstatements before normal data-migration bookkeeping. D1 executes those as remote database operations, so a warm MCP session start can pay the schema bring-up cost again even though nothing changed.Moving schema preparation only to the edge Worker would make the common path faster, but it would couple Durable Object correctness to edge startup. A session DO can wake independently, so this keeps the safety check inside the shared D1 opener.
Change
first-primaryD1 session so a matching value is current even if read replication is enabled later.runCloudflareDataMigrations()'s existing return contract; the new internal preparation result only exposes whether compatibility changed the schema.Data migrations still consult their own ledger on every open. A migration-only release therefore does not depend on the schema fingerprint changing.
Safety properties
connection.item_idcompatibility rebuilds get a final schema ensure before stamping, preserving newer nullable columns and indexes.Verification
The new regression suite covers:
connectionrebuild ends withitem_ids,last_health, andconnection_uidxbefore stamping; andBefore the change, the first test fails with all 46 schema statements present on the second open.
Merge-ready gates run locally:
bun run format:checkbun run lintbun run typecheck— 43/43 packagesTURBO_TEST_CONCURRENCY=2 bun run test— 37/37 package tasksbun run --cwd apps/host-cloudflare test— 22/22 tests, including the real workerd/Miniflare MCP flowNo changeset:
@executor-js/host-cloudflareis private.Prior work checked
No existing issue or PR title covers repeated Cloudflare D1 schema preparation. #1313 addresses session-start serialization, while #1409 reuses an already-open local/self-host database; neither changes this D1 path.