d1-migration
Cloudflare D1 migration workflow: generate with Drizzle, inspect SQL for gotchas, apply to local and remote, fix stuck migrations, handle partial failures. Use when running migrations, fixing migration errors, or setting up D1 schemas.
npx skills add jezweb/claude-skills --skill d1-migration --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# D1 Migration Workflow Guided workflow for Cloudflare D1 database migrations using Drizzle ORM. ## Standard Migration Flow ### 1. Generate Migration ```bash pnpm db:generate ``` This creates a new `.sql` file in `drizzle/` (or your configured migrations directory). ### 2. Inspect the SQL (CRITICAL) **Always read the generated SQL before applying.** Drizzle sometimes generates destructive migrations for simple schema changes. #### Red Flag: Table Recreation If you see this pattern, the migration will likely fail: ```sql CREATE TABLE `my_table_new` (...); INSERT INTO `my_table_new` SELECT ..., `new_column`, ... FROM `my_table`; -- ^^^ This column doesn't exist in old table! DROP TABLE `my_table`; ALTER TABLE `my_table_new` RENAME TO `my_table`; ``` **Cause**: Changing a column's `default` value in Drizzle schema triggers full table recreation. The INSERT SELECT references the new column from the old table. **Fix**: If you're only adding new columns (no type/constraint changes on existing columns), simplify to: ```sql ALTER TABLE `my_table` ADD COLUMN `new_column` TEXT DEFAULT 'value'; ``` Edit the `.sql` file directly before applying. ### 3. Apply to Local ```bash pnpm db:migrate:lo
- Standard Migration Flow
- 1. Generate Migration
- 2. Inspect the SQL (CRITICAL)
- 3. Apply to Local
- 4. Apply to Remote
- 5. Verify
- Fixing Stuck Migrations
- Diagnosis
- Fix
- Prevention
- Bulk Insert Batching
- Column Naming
- New Project Setup
pnpm db:generate pnpm db:migrate:local pnpm db:migrate:remote Check local npx wrangler d1 execute DB_NAME --local --command "PRAGMA table_info(my_table)" Check remote npx wrangler d1 execute DB_NAME --remote --command "PRAGMA table_info(my_table)" npx wrangler d1 execute DB_NAME --remote \ pnpm db:migrate
What does the d1-migration skill do?
Cloudflare D1 migration workflow: generate with Drizzle, inspect SQL for gotchas, apply to local and remote, fix stuck migrations, handle partial failures. Use when running migrations, fixing migration errors, or setting up D1 schemas.
How do I install it?
Run `npx skills add jezweb/claude-skills --skill d1-migration --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From jezweb/claude-skills, a repository with 954 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
