Skip to content

Commit 97a3a1b

Browse files
committed
fix(cloud): strip DO migrations from preview deploy config so PR builds stop failing
Preview (non-main) Workers Builds deploy via 'wrangler versions upload', which rejects any config containing Durable Object migrations (error 10211). Previews share production's already-applied DO state, so they neither need nor can apply migrations. build.mjs strips 'migrations' from the generated dist/server/wrangler.json on non-main CI branches; main keeps them and applies on the real deploy. Fail-safe: only strips on a confirmed non-main CI branch, never on a production deploy. Leaves the orphaned KV McpSessionDO + its stub export in place (harmless, unbound); not worth a delete migration whose own preview build can't pass.
1 parent 8109db1 commit 97a3a1b

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

apps/cloud/scripts/build.mjs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import { spawnSync } from "node:child_process";
1111
import { randomBytes } from "node:crypto";
12-
import { rmSync } from "node:fs";
12+
import { readFileSync, rmSync, writeFileSync } from "node:fs";
1313

1414
if (!process.env.VITE_PUBLIC_ANALYTICS_PATH) {
1515
process.env.VITE_PUBLIC_ANALYTICS_PATH = randomBytes(4).toString("hex");
@@ -32,3 +32,26 @@ for (const step of steps) {
3232
process.exit(result.status ?? 1);
3333
}
3434
}
35+
36+
// Preview (non-production) Cloudflare Workers Builds deploy via `wrangler versions
37+
// upload`, which REJECTS any config containing an unapplied Durable Object
38+
// migration (error 10211 — "migrations must be applied via a non-versioned
39+
// deployment"). Preview versions share production's already-applied DO state, so
40+
// they neither need nor can apply migrations. Strip `migrations` from the
41+
// generated deploy config on non-`main` CI branches so PR preview builds stop
42+
// failing. Production (`main`) keeps migrations and applies them on the real,
43+
// non-versioned deploy. Fail-safe: only triggers on a confirmed non-`main` CI
44+
// branch, so it can never drop migrations from a production deploy.
45+
const ciBranch = process.env.WORKERS_CI_BRANCH;
46+
if (process.env.WORKERS_CI === "1" && ciBranch && ciBranch !== "main") {
47+
const cfgUrl = new URL("../dist/server/wrangler.json", import.meta.url);
48+
const cfg = JSON.parse(readFileSync(cfgUrl, "utf8"));
49+
if (Array.isArray(cfg.migrations) && cfg.migrations.length > 0) {
50+
delete cfg.migrations;
51+
writeFileSync(cfgUrl, JSON.stringify(cfg));
52+
console.log(
53+
`[build] preview branch '${ciBranch}': stripped Durable Object migrations from ` +
54+
`dist/server/wrangler.json (versions upload cannot apply migrations)`,
55+
);
56+
}
57+
}

0 commit comments

Comments
 (0)