D1 Migration Workflow
A practical playbook for generating, reviewing, and applying Cloudflare D1 migrations with Drizzle — including recovery from stuck migrations.
Dev & CodingIntermediate★ 981⑂ 101AI score 8/10Last updated: Jul 2, 2026
What it does
- Forces an inspection step on SQL generated by
pnpm db:generate, flagging Drizzle's destructive "table recreation" pattern (CREATE new → INSERT SELECT → DROP → RENAME) that appears when you only change a columndefault, and rewriting it as a simpleALTER TABLE ADD COLUMN. - Applies migrations to both local and remote (
--local/--remote) and verifies withPRAGMA table_infoso you avoid "works locally, breaks in prod". - Diagnoses and repairs stuck/partially applied migrations by querying the
d1_migrationstable and manually recording the missing entry. - Provides a batching pattern to avoid D1's silent failure when bulk INSERT exceeds the ~100–150 parameter limit.
- Documents column naming conventions (Drizzle camelCase vs raw SQL snake_case) and the correct new-project order: deploy Worker → create D1 → copy database_id into wrangler.jsonc → redeploy → migrate.
Who it's for
- Backend/full-stack developers on Cloudflare Workers + D1 + Drizzle ORM.
- Teams repeatedly bitten by drifted local vs remote database state.
- Anyone tired of looking up wrangler d1 CLI syntax.
Examples
- You add a column to your Drizzle schema and ask Claude to "generate and apply the migration" — it reads the SQL first, rewrites a table-recreation migration into a safe ALTER, then applies to local and remote.
db:migratefails with a duplicate column error — Claude checksPRAGMA table_infoandd1_migrations, records the stuck migration, and continues the remaining ones.- A 500-row seed insert silently fails — Claude refactors it into a 10-row batched loop.
· · · Install guide · · ·
Try it now, no install
Paste this into Claude to use the skill without installing anything.
Read the instructions in this file and follow them to help me: https://raw.githubusercontent.com/jezweb/claude-skills/HEAD/plugins/cloudflare/skills/d1-migration/SKILL.md What I want: (describe your task here)
If Claude can't open the link, open it yourself and paste the contents instead.
↓ If it works for you, download the ZIP below and install it. Then it runs on its own — no pasting each time.
Install in the Claude app (no terminal)
- Download the ZIP with the button below.
- In Claude, open Settings → Capabilities and turn on 'Code execution and file creation'. (one time)
- Go to Customize → Skills → + → 'Upload a skill' and upload the ZIP.
Install in Claude Code
Let Claude do it — paste this into Claude Code
Install the skill I found on Claude Skill Mart. Copy the plugins/cloudflare/skills/d1-migration folder from the GitHub repo jezweb/claude-skills into my ~/.claude/skills/d1-migration/. When it's done, tell me in one line what this skill can do.
Install with a command instead
git clone https://github.com/jezweb/claude-skills.git && mkdir -p ~/.claude/skills && cp -r claude-skills/plugins/cloudflare/skills/d1-migration ~/.claude/skills/⚠ This is a third-party skill. Check the source repository before installing.
- Install Claude Code and open a terminal.
- Clone the repo:
git clone https://github.com/jezweb/claude-skills.git - Create the skills folder:
mkdir -p ~/.claude/skills - Copy the skill:
cp -r claude-skills/plugins/cloudflare/skills/d1-migration ~/.claude/skills/ - Confirm
~/.claude/skills/d1-migration/SKILL.mdexists. - Make sure your project has wrangler and Drizzle installed, plus
db:generate/db:migrate:local/db:migrate:remotescripts. - Restart Claude Code inside your project and say "generate and apply a D1 migration" to trigger the skill.
View source on GitHub ↗License: MIT