Skip to content

fix(worker): wire D1 migrations_dir + correct deploy runbook (GOAP-252) - #1019

Merged
d-o-hub merged 1 commit into
mainfrom
fix/worker-api-deploy-gaps
Aug 21, 2026
Merged

fix(worker): wire D1 migrations_dir + correct deploy runbook (GOAP-252)#1019
d-o-hub merged 1 commit into
mainfrom
fix/worker-api-deploy-gaps

Conversation

@d-o-hub

@d-o-hub d-o-hub commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

What & why

Follow-up to PR #1018 (GOAP-252 / issue #1014): the release now deploys the worker and asserts /api/health, but two more credential-free blockers would have broken the deploy even with credentials:

1. D1 migrations could never apply (wrangler.jsonc)

The Worker's runtime DB is D1 (env.DB), and all 12 migrations live in packages/schema/migrations/ — but wrangler.jsonc had no migrations_dir, so wrangler d1 migrations apply (and deploy-time migrations) would find nothing. The database would deploy empty: every query fails, login included.

→ Added migrations_dir: "../packages/schema/migrations" to the D1 binding. Verified with wrangler deploy --dry-run (config parses; bindings listed).

2. Runbook provisioned the wrong DB + placeholder origins (docs/runbooks/infrastructure-setup.md)

  • Told operators to create a Turso DB — Turso is only used by the legacy demo-account seed script and the demo fail-closed detection; the Worker queries D1.
  • APP_BASE_URL=https://do-epub-studio.example.com — a nonexistent domain baked into CORS, recovery emails, and signed file URLs.
  • No WebAuthn secrets — WEBAUTHN_RP_ID=localhost / WEBAUTHN_ORIGIN=http://localhost:5173 defaults would break admin passkey login.
  • No VITE_API_BASE_URL step — the web build only calls the Worker cross-origin when that env is baked in at build time.

→ Rewrote the runbook: D1 provisioning + migrations_dir, real production origins (https://do-epub-studio.onrender.com frontend / https://api.do-epub-studio.workers.dev API), WebAuthn secrets, KV namespace step, VITE_API_BASE_URL build step, deploy + /api/health verification, and a GOAP-252 API-contract checklist.

Verification

  • pnpm exec wrangler deploy --config wrangler.jsonc --dry-run — passes, bindings correct
  • node scripts/check-adr-index.mjs — passes
  • Docs link validation (same checks as docs-validation.yml) — no broken links
  • No source code changed — worker tests/typecheck unaffected

Remaining (credentials, tracked in #1014)

Provision D1/KV/R2, add CLOUDFLARE_API_TOKEN + CLOUDFLARE_ACCOUNT_ID secrets, set Worker secrets (APP_BASE_URL/WebAuthn/etc.), deploy, set VITE_API_BASE_URL on Render, rebuild.

wrangler.jsonc bound D1 but had no migrations_dir, so the 12 schema
migrations could never apply. The runbook provisioned Turso (only used by
the legacy seed script) and used placeholder domains for APP_BASE_URL and
WebAuthn, which would break CORS, recovery links, signed URLs, and
passkeys even after a successful deploy. Point migrations at
packages/schema/migrations and document the real production origins plus
VITE_API_BASE_URL.

Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
@d-o-hub
d-o-hub requested a review from d-oit as a code owner August 20, 2026 19:29
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 20, 2026

Copy link
Copy Markdown

Deploying do-epub-studio with  Cloudflare Pages  Cloudflare Pages

Latest commit: e623b03
Status: ✅  Deploy successful!
Preview URL: https://6c728ee6.do-epub-studio.pages.dev
Branch Preview URL: https://fix-worker-api-deploy-gaps.do-epub-studio.pages.dev

View logs

@github-actions github-actions Bot added documentation Improvements or additions to documentation area:worker labels Aug 20, 2026
@codacy-production

Copy link
Copy Markdown
Contributor

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@d-o-hub
d-o-hub merged commit 0d366e7 into main Aug 21, 2026
27 checks passed
@d-o-hub
d-o-hub deleted the fix/worker-api-deploy-gaps branch August 21, 2026 06:55
d-o-hub added a commit that referenced this pull request Aug 21, 2026
)

PR #1019 wired migrations_dir as `../packages/schema/migrations`, which
resolves relative to apps/worker/ to the nonexistent apps/packages path —
`wrangler d1 migrations apply` could never find the 12 migrations. The
placeholder database_id/KV id also blocked migration application, and
APP_BASE_URL/WebAuthn still pointed at example.com/localhost.

Replace placeholders with the provisioned resources (D1 do-epub-studio,
KV CACHE_KV), correct migrations_dir to ../../packages/schema/migrations,
and set real Pages origins so no deploy path bakes in placeholder domains.

🤖 Generated with Codebuff

Co-authored-by: d-oit <d-oit@users.noreply.github.com>
Co-authored-by: Codebuff <noreply@codebuff.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:worker documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants