Cloudflare D1: a zero-infrastructure database for SaaS on Workers
Use Cloudflare D1 as the database for a ShipAny app on Cloudflare Workers — create the database, bind it, apply Drizzle migrations remotely and seed RBAC.
Last updated: Oct 8, 2026
Cloudflare D1 is a serverless SQLite database that lives next to your Worker. It's the default database when you deploy ShipAny TanStack to Cloudflare: no servers, no connection strings, no pooling to think about.
What ShipAny handles
- A D1 driver that reads the
DBbinding from the Workers environment — no URL needed. - The SQLite schema for all built-in tables, applied with Drizzle migrations.
- Bundle trimming: when
DATABASE_PROVIDERisd1, the other database drivers are stubbed out of the Worker bundle. - One-command setup with the
deploy-cloudflareagent skill: it creates the database, writes the binding, applies migrations, seeds roles and permissions, and is safe to re-run.
Setup
- Create the database:
npx wrangler d1 create <name>and copy thedatabase_id. - In
wrangler.jsonc, setvars.DATABASE_PROVIDERto"d1"and add the binding:
"d1_databases": [
{ "binding": "DB", "database_name": "<name>", "database_id": "<id>", "migrations_dir": "drizzle" }
]
- Generate and apply migrations:
pnpm db:generate, thennpx wrangler d1 migrations apply <name> --remote. - Seed roles and permissions, then deploy with
pnpm run cf:deploy.
Tips
- D1 is for Cloudflare Workers deploys. Locally, the same schema runs on a plain SQLite file.
migrations_dirmust point atdrizzle, or wrangler won't find any migrations to apply.- Outgrowing D1 or need Postgres features? Switch to PostgreSQL through Hyperdrive.
