Skip to content

TP1: a database per user on Workers - #2

Merged
pullely merged 1 commit into
mainfrom
orun/TP-2-a-database-per-user-on-workers
Oct 29, 2026
Merged

pullely merged 1 commit into
mainfrom
orun/TP-2-a-database-per-user-on-workers

Conversation

@pullely

@pullely pullely commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

notrab/turso-per-user-starter (main 590144a; no licence anywhere — no LICENSE file, no package.json licence, no README section, none on GitHub) in apps/web: Next.js 16.3.8 (upstream's 14; OpenNext 1.20 refuses 15.5) with React 19 and Clerk 7 (auth() awaited, auth.protect(), middleware.ts as Next 16's proxy.ts), built by next build --webpack and then @opennextjs/cloudflare (standalone output, the static-assets incremental cache) into one Worker with Static Assets, 1.94 MiB gzipped — inside Workers Free. Turso stays the SaaS it is upstream: each user's database (md5 of their Clerk id) is created through Turso's Platform API (@tursodatabase/api 1.9, its global fetch) from the owner's seed database in the default group, and the dashboard's server actions read and write it through drizzle over @libsql/client/web (libSQL's HTTP protocol; the Node entry carries a native module) with the group's token; @libsql/isomorphic-ws is traced whole (outputFileTracingIncludes), because the build traces libSQL — a Next server-external package — for Node and the Worker resolves its workerd export. app/utils.ts became lib/turso.ts (the Turso switch, the Platform API calls), lib/db.ts (the user's database) and lib/todos.ts (the queries). Clerk's webhook verifies Svix's signature against the raw body before parsing it (upstream verified a re-serialised req.json()), creates a database only for a signed user.created, and answers 503 without its secret (upstream threw). Clerk is connected when the build had both its keys (lib/clerk.ts, clerk-auth-starter's switch); without them there is no ClerkProvider, the proxy passes requests through, and sign-up, sign-in and the dashboard say Clerk is not connected yet. Turso's four values are read per request: without them the dashboard names what is missing and /dump.sql answers 503, never a 500 (upstream's Platform API client threw on import); the authenticated layout is force-dynamic so no build bakes that answer in. The build runs without the Worker's six keys (env -u; told of Clerk's secret key only that it exists, CLERK_SECRET_KEY_SET) and tooling/wire/worker-secrets.mjs hands them to the Worker as Worker secrets from a deploy lane; the component reads all seven as optional Orun secret refs. Inter is self-hosted, the Open Graph image is served from public/, the site's name one seam (SITE_NAME in app/site.ts, the landing's heading and title), metadataBase NEXT_PUBLIC_SITE_URL, and the landing's "GitHub Repo" and the user menu's "Star repository" the site's own source link. /api/health is the deploy's smoke (ok unless a Clerk-built Worker lacks CLERK_SECRET_KEY; Clerk, Turso and the webhook reported). tests/web: identity and the Clerk switch, Turso's connection and its Platform API calls against a local stand-in (the template's create request), the webhook against Svix-signed deliveries (forged, stale, altered and re-serialised refused), the todo queries on a real libSQL file through the libsql client's file mode, seeded from migrations/ and from dump.sql, and the secret push. typecheck, lint, test and build are green; wrangler dev serves the site not connected, and — with made-up Clerk and Turso keys — answers a signed-out visitor with Clerk's middleware and creates a user's database at a stand-in of the Platform API from a signed webhook.

🤖 Generated with Claude Code

notrab/turso-per-user-starter (main 590144a; no licence anywhere — no LICENSE file, no package.json licence, no README section, none on GitHub) in apps/web: Next.js 16.3.8 (upstream's 14; OpenNext 1.20 refuses 15.5) with React 19 and Clerk 7 (auth() awaited, auth.protect(), middleware.ts as Next 16's proxy.ts), built by next build --webpack and then @opennextjs/cloudflare (standalone output, the static-assets incremental cache) into one Worker with Static Assets, 1.94 MiB gzipped — inside Workers Free. Turso stays the SaaS it is upstream: each user's database (md5 of their Clerk id) is created through Turso's Platform API (@tursodatabase/api 1.9, its global fetch) from the owner's seed database in the default group, and the dashboard's server actions read and write it through drizzle over @libsql/client/web (libSQL's HTTP protocol; the Node entry carries a native module) with the group's token; @libsql/isomorphic-ws is traced whole (outputFileTracingIncludes), because the build traces libSQL — a Next server-external package — for Node and the Worker resolves its workerd export. app/utils.ts became lib/turso.ts (the Turso switch, the Platform API calls), lib/db.ts (the user's database) and lib/todos.ts (the queries). Clerk's webhook verifies Svix's signature against the raw body before parsing it (upstream verified a re-serialised req.json()), creates a database only for a signed user.created, and answers 503 without its secret (upstream threw). Clerk is connected when the build had both its keys (lib/clerk.ts, clerk-auth-starter's switch); without them there is no ClerkProvider, the proxy passes requests through, and sign-up, sign-in and the dashboard say Clerk is not connected yet. Turso's four values are read per request: without them the dashboard names what is missing and /dump.sql answers 503, never a 500 (upstream's Platform API client threw on import); the authenticated layout is force-dynamic so no build bakes that answer in. The build runs without the Worker's six keys (env -u; told of Clerk's secret key only that it exists, CLERK_SECRET_KEY_SET) and tooling/wire/worker-secrets.mjs hands them to the Worker as Worker secrets from a deploy lane; the component reads all seven as optional Orun secret refs. Inter is self-hosted, the Open Graph image is served from public/, the site's name one seam (SITE_NAME in app/site.ts, the landing's heading and title), metadataBase NEXT_PUBLIC_SITE_URL, and the landing's "GitHub Repo" and the user menu's "Star repository" the site's own source link. /api/health is the deploy's smoke (ok unless a Clerk-built Worker lacks CLERK_SECRET_KEY; Clerk, Turso and the webhook reported). tests/web: identity and the Clerk switch, Turso's connection and its Platform API calls against a local stand-in (the template's create request), the webhook against Svix-signed deliveries (forged, stale, altered and re-serialised refused), the todo queries on a real libSQL file through the libsql client's file mode, seeded from migrations/ and from dump.sql, and the secret push. typecheck, lint, test and build are green; wrangler dev serves the site not connected, and — with made-up Clerk and Turso keys — answers a signed-out visitor with Clerk's middleware and creates a user's database at a stand-in of the Platform API from a signed webhook.

Co-Authored-By: Claude <noreply@anthropic.com>
Orun-Task: TP-2
@pullely
pullely merged commit 1437a7e into main Oct 29, 2026
2 checks passed
@pullely
pullely deleted the orun/TP-2-a-database-per-user-on-workers branch October 29, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants