Rebase Drizzle Migration
Fix drizzle migrations after rebasing onto upstream/main when migrations diverged
Install
npx skills add humanlayer/humanlayer --skill rebase-drizzle-migration -g -a claude-code -y- Repository
- humanlayer/humanlayer12.7k
- Category
- Engineering
- Updated
- 4d ago
- License
- Apache-2.0
- Context cost
- Lightabout 1,418 tokens
- Runs scripts
- No, instructions only
What it does
fix drizzle migrations after rebasing onto upstream/main when migrations diverged
Rebase Drizzle Migration
Guide the user through recovering from a messy drizzle migration state after rebasing onto upstream/main.
Agent Workflow
- Diagnose - Analyze the current state and identify what's wrong
- Explain - Tell the user what happened and why
- Fix - Run the necessary commands to fix the migration state
- Verify - Check results after each step
Diagnosis Phase
When this skill is invoked, first diagnose the problem:
# Check for duplicate journal entries
cat packages/db/drizzle/meta/_journal.json | tail -30
# List migration files
ls packages/db/drizzle/*.sql
# Check diff against upstream
git diff upstream/main --stat -- packages/db/
# Check what upstream has
git show upstream/main:packages/db/drizzle/meta/_journal.json | tail -20
# Find the merge base
git merge-base HEAD upstream/main
Look for:
- Duplicate
idxvalues in journal - Same migration
tagappearing twice - Migration files that exist on branch but not upstream (or vice versa)
- Schema files that don't match upstream's expected state
The Problem (Explain to User)
Drizzle migrations are sequential and tracked in packages/db/drizzle/meta/_journal.json. The issue occurs when:
- You branched off main at migration
0008 - You added your own migration
0009(or overwrote0008) - Meanwhile, upstream added their own
0009 - You rebased onto upstream
This results in:
- Conflicting or duplicate migration files
- A corrupted journal with duplicate entries or wrong indices
- Snapshot files that don't match the journal
drizzle-kit generateasking nonsensical questions about column renames
Fix Process
Step 1: Checkout upstream/main
Switch to upstream/main to get a clean database state:
git checkout upstream/main
Step 2: Apply migrations to database
Run the migration command:
bun --bun --cwd packages/db drizzle-kit migrate
