d1-migration

Solid

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.

API & Backend 809 stars 82 forks Updated 2 weeks ago MIT

Install

View on GitHub

Quality Score: 93/100

Stars 20%
97
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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:local # or: npx wrangler d1 migrations apply DB_NAME --local ``` ### 4. Apply to Remote ```bash pnpm db:migrate:remote # or: npx wrangler d1 migrations apply DB_NAME --remote ``` **Always apply to BOTH local and remote before testing.** Local-onl...

Details

Author
jezweb
Repository
jezweb/claude-skills
Created
7 months ago
Last Updated
2 weeks ago
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

API & Backend Solid

d1-drizzle-schema

Generate Drizzle ORM schemas for Cloudflare D1 databases with correct D1-specific patterns. Produces schema files, migration commands, type exports, and DATABASE_SCHEMA.md documentation. Handles D1 quirks: foreign keys always enforced, no native BOOLEAN/DATETIME types, 100 bound parameter limit, JSON stored as TEXT. Use when creating a new database, adding tables, or scaffolding a D1 data layer.

809 Updated 2 weeks ago
jezweb
API & Backend Solid

drizzle-orm-d1

Type-safe ORM for Cloudflare D1 databases using Drizzle. Use when: building D1 database schemas, writing type-safe SQL queries, managing migrations with Drizzle Kit, defining table relations, implementing prepared statements, using D1 batch API, or encountering D1_ERROR, transaction errors, foreign key constraint failures, or schema inference issues. Keywords: drizzle orm, drizzle d1, type-safe sql, drizzle schema, drizzle migrations, drizzle kit, orm cloudflare, d1 orm, drizzle typescript, drizzle relations, drizzle transactions, drizzle query builder, schema definition, prepared statements, drizzle batch, migration management, relational queries, drizzle joins, D1_ERROR, BEGIN TRANSACTION d1, foreign key constraint, migration failed, schema not found, d1 binding error, schema design, database indexes, soft deletes, uuid primary keys, enum constraints, performance optimization, naming conventions, schema testing

160 Updated 2 weeks ago
secondsky
API & Backend Listed

database-development

Database migrations and Drizzle ORM guidelines for the vm0 project

1,116 Updated today
vm0-ai
DevOps & Infrastructure Solid

cloudflare-d1

Cloudflare D1 serverless SQLite on edge. Use for databases, migrations, bindings, or encountering D1_ERROR, statement too long, too many requests queued errors.

160 Updated 2 weeks ago
secondsky
AI & Automation Listed

drizzle-migration-conflict-resolution

Resolve Drizzle migration merge/rebase conflicts in OneQuery by rewinding local-only migration history and regenerating migration metadata. Use when conflicts involve packages/db/src/migrations/meta/_journal.json, migration SQL files in packages/db/src/migrations/*.sql, or migration snapshots in packages/db/src/migrations/meta/*_snapshot.json.

11 Updated 2 days ago
wordbricks