Database Migrations
Review and apply D1 migrations with backups and release checks.
D1 / SQLite uses its own reviewed migration history.
| Schema | Configuration | Migrations |
|---|---|---|
packages/db/src/schema-d1.ts | packages/db/drizzle.config.d1.ts | packages/db/migrations-d1/ |
D1
pnpm db:generate:d1
pnpm db:migrate:d1:local
pnpm db:seed:d1
pnpm db:migrate:d1:status
pnpm db:migrate:d1:remote
pnpm db:migrate:d1:status --strictThe generator maintains SQL hashes in packages/db/migrations-d1/manifest.json and refuses changes to recorded migrations. Remote migration exports a backup, tests the migration and foreign keys on a local clone, then applies the migration remotely. The migration script reads the database name from the DB binding in apps/web-cloudflare/wrangler.jsonc. Set the production database name and ID there.
Before a Workers Builds release that needs a new migration, apply it and run pnpm db:migrate:d1:status --strict before pushing or merging to the production branch. The GitHub Actions workflow and direct Linux releases with pnpm cf:deploy both run this check and stop when migrations are pending. Cloudflare deployment
Existing Databases
The latest version resets the baseline. Do not apply the new 0000_initial.sql as an upgrade migration to an existing production database. Legacy databases may have old journals and settings tables: back up, compare schema/history on a clone, and design incremental migrations for your derivative. Current root scripts have neither a legacy settings export command nor drizzle:* aliases.
Write failing tests first. Append migrations instead of rewriting applied SQL or faking journals. Test the selected schema, SQL queries, defaults, indexes, and failure recovery before release.