d1-migration

Generates, inspects, and applies Cloudflare D1 database migrations using Drizzle ORM and wrangler.

1|Updated Aug 18, 2026
One-click install
npx skills add https://github.com/scsm-unrestrict/dsh-frontend-engineer-agent --skill d1-migration-scsm-unrestrict
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: d1-migration
Source: https://github.com/scsm-unrestrict/dsh-frontend-engineer-agent/tree/main/frontend-engineer/skills/d1-migration
Command: npx skills add https://github.com/scsm-unrestrict/dsh-frontend-engineer-agent --skill d1-migration-scsm-unrestrict

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Cloudflare D1 migrations generated by Drizzle ORM can silently fail, recreate tables destructively, or get stuck in a partially applied state, causing confusing "works locally, breaks in production" bugs. ## Core Features & Use Cases - Safe Migration Workflow: Generate migrations with Drizzle, inspect the SQL for destructive table-recreation patterns, then apply to both local and remote D1 databases. - Stuck Migration Recovery: Diagnose partially applied migrations by querying d1_migrations and PRAGMA table_info, then manually record the migration to unblock the pipeline. - Bulk Insert Batching: Avoid D1's parameter limit failures by chunking large multi-row INSERTs into batches of 10 rows. - Use Case: You changed a column default in your Drizzle schema and the generated migration fails with a duplicate column error. Use this workflow to inspect the SQL, verify the column exists, record the migration manually, and apply the remaining migrations. ## Quick Start Ask the agent to generate and apply a new D1 migration for your Drizzle schema, inspecting the SQL first and applying it to both local and remote databases.

Frequently Asked Questions about d1-migration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run Cloudflare D1 migrations with Drizzle ORM?

Generate the migration with `pnpm db:generate`, inspect the produced SQL file for destructive patterns, then apply it with `wrangler d1 migrations apply DB_NAME --local` and again with `--remote`. Always apply to both environments before testing.

How do I fix a stuck or partially applied D1 migration?

Verify the column or table exists with `PRAGMA table_info`, check recorded migrations via `SELECT * FROM d1_migrations`, then manually insert the missing migration record into `d1_migrations`. After that, run the remaining migrations normally.

Why does Drizzle generate a table recreation for a simple schema change?

Changing a column's default value in the Drizzle schema triggers full table recreation, and the generated INSERT SELECT references the new column from the old table, which fails. If you only added columns, rewrite the SQL as a simple `ALTER TABLE ADD COLUMN` statement.

Why do bulk inserts fail silently on Cloudflare D1?

D1 fails when rows multiplied by columns exceeds roughly 100-150 parameters in a single statement. Batch inserts into chunks of about 10 rows per query to stay under the limit.

Does SQLite support ALTER TABLE ADD COLUMN IF NOT EXISTS?

No, SQLite has no `IF NOT EXISTS` variant for `ALTER TABLE ADD COLUMN`. Check column existence first with `PRAGMA table_info` or handle the duplicate-column error in application code.