Database
How Cloudflare D1 and the Prisma tooling schema are configured
@repo/database talks to Cloudflare D1 at runtime through the DB Workers binding (raw SQL
store — no Prisma query-compiler WASM in the Worker bundle). The Prisma schema in
packages/database/prisma/schema.prisma (provider = "sqlite") and the SQL files under
packages/database/migrations/ are the single source of truth for schema changes; Wrangler applies
them with bun run migrate / bun run migrate:deploy.
Domain tables are still mostly unbuilt
Workspace and ClerkWebhookReceipt are implemented. None of the remaining entities in
the domain model — Task, Run, Agent, Machine, Event, Artifact,
Document, Approval — has a table yet.
What the package provides
- Declarative schema in
prisma/schema.prisma(tooling). - D1 migrations in
packages/database/migrations/. - Runtime facade
databasewith Prisma-shaped accessors backed by raw D1. - Workspace provisioning helpers used by Clerk webhooks and authenticated routes.
Usage
import { database } from '@repo/database';
const Page = async () => {
const workspace = await database.workspace.findUnique({
where: { clerkOrgId: 'org_…' },
});
};The DB binding must be declared in the app's wrangler.jsonc. There is no runtime
DATABASE_URL. Optional DATABASE_URL in packages/database/.env is only for local Prisma
tooling / SQLite integration tests.
Creating migrations
bun run migrate:diff # render SQL for the schema change
bun run migrate # apply to local D1
bun run migrate:deploy # apply to remote D1See Cloudflare deployment for bindings and Workers topology.