Skip to content

Provision the D1 database so the v1alpha review API can serve traffic #543

Description

@richardthe3rd

The /v1alpha review API has shipped code but no storage. It has never served a request.

Current state

cloudflare-worker/wrangler.toml has its [[d1_databases]] block commented out, so the deployed worker has no RATINGS_DB binding. cloudflare-worker/reviews.ts:158 detects this and returns 503 UNAVAILABLE / STORAGE_UNCONFIGURED for every /v1alpha route.

This is deliberate, not an accident. The block previously carried a placeholder database_id of all zeroes for a database that was never created. Cloudflare validates bindings at script upload, so every wrangler deploy failed with error 10181 — taking the whole worker down, CORS proxy included. That broke worker deploys from 2026-06-13 (#426) until PR #542, which disabled the binding to restore deployability.

So the API's degraded mode is now honest (503 rather than a fall-through 404 from the upstream origin), but still non-functional.

What needs doing

Requires Cloudflare account access — an agent cannot do this.

cd cloudflare-worker
wrangler d1 create cbf-myfestival                      # returns the real database_id
# uncomment [[d1_databases]] in wrangler.toml, paste the id into database_id
wrangler d1 migrations apply cbf-myfestival --remote   # migrations/0001_create_reviews_table.sql

--remote is mandatory: without it wrangler migrates only the local simulation and reports success while the real database stays unmigrated.

The CLOUDFLARE_API_TOKEN needs D1: Edit on top of its existing Workers Scripts / Pages scopes.

Gotchas

  • cloudflare-worker/test/wrangler-config.test.js will fail once the binding is uncommented. That is intentional — it forces the no D1 binding tests in test/reviews.test.js and the README's D1 section to be updated in the same change, then the expectation flipped to true.
  • Neither npm test nor wrangler deploy --dry-run can confirm the binding resolves. The vitest pool uses a simulated local D1 that ignores the id, and --dry-run exits 0 on a dangling binding (verified, wrangler 4.98.0). Only a real deploy proves it.
  • cloudflare-worker/ is on the Do-Not-Modify list and the festival-freeze rule applies to live infra changes — check the freeze window before provisioning or migrating.

Verification once provisioned

curl -X PATCH https://data.cambeerfestival.app/v1alpha/festivals/cbf2026/drinks/beer-1/review \
  -H 'Content-Type: application/json' -H 'X-Device-Id: test-device' \
  -d '{"starRating":4}'
curl https://data.cambeerfestival.app/v1alpha/festivals/cbf2026/reviewSummaries/beer-1

Writes from any origin other than https://cambeerfestival.app land in the test bucket, so this is safe to run against production.

Prerequisite for the cloud-sync half of the My Festival work (#315). Related: #432, #72.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions