Bun workspaces:
packages/db: D1 schema (drizzle) and SQL migrations, shared byworkerandviewworker: Cloudflare Worker that records clicks on the festival websiteview: SvelteKit dashboard on Cloudflare Pages
Install dependencies at the repository root:
bun installEdit packages/db/src/schema.ts, then generate a migration:
bun db:generateApply migrations (from worker/):
cd worker
bun db:migrate:local # local D1 for development
bun db:migrate:remote # production D1deploy:
cd view; bun run deployBesides recording clicks, a cron trigger (every 10 minutes) imports Cloudflare Analytics
into D1 (traffic_pageviews from Web Analytics, traffic_requests from HTTP requests).
Progress is kept per source in ingest_state; see worker/src/ingest/.
The import needs an API token with the "Account Analytics Read" permission (without it the cron only logs and skips).
For wrangler dev, copy worker/.dev.vars.example to worker/.dev.vars.
First deploy (from worker/):
bun db:migrate:remote # 1. create the tables
bunx wrangler secret put CF_ANALYTICS_TOKEN # 2. set the token
bun run deploy # 3. deploy (the cron imports the last hour)
CF_ANALYTICS_TOKEN=... bun backfill --from 2026-11-01 --to 2026-11-21 --remote --apply # 4. older databun backfill queries the API in 6-hour chunks (data older than ~30 days is unavailable) and writes a SQL file;
without --apply it only prints the wrangler d1 execute command. Use --source pageviews|requests to limit it
and --local to target the local D1. It replaces the rows of the requested range and never touches ingest_state,
so it is safe to run while the cron is active.
Subsequent deploys:
cd worker; bun run deploy