infrastructure//Cloudflare//D1

D1 is Cloudflare's managed SQLite database. It runs at the edge, close to the Workers, and speaks standard SQL because it is SQLite underneath.


D1 is Cloudflare's managed SQLite database. It runs at the edge, close to the Workers, and speaks standard SQL because it is SQLite underneath.

There are two copies: a local one for development, run through wrangler, and a remote one in production on Cloudflare's infrastructure.

Migrations run with npx wrangler d1 migrations apply --local in development or --remote in production. They generate a schema.ts that is applied to each database independently.

Pushing data from local to remote is npx wrangler d1 export --local --output dump.sql followed by npx wrangler d1 execute --remote --file dump.sql; pulling from remote to local is npx wrangler d1 export --remote --output dump.sql followed by npx wrangler d1 execute --local --file dump.sql. The dump.sql is only a transport file, like a pendrive: extract from one side, inject into the other, delete the file.

Code deploys (GitHub Actions or wrangler pages deploy) push the frontend and the API only and never touch D1. The database lives on Cloudflare separately, GitHub does not know it exists, and .wrangler/ (the local database) is in .gitignore.

The free tier gives 5 GB of storage and 5 million rows read per day. D1 is single-writer (no concurrent writes from several workers) with eventually consistent reads from replicas, which suits read-heavy apps, personal projects and small-to-medium SaaS.