Skills

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

  1. Diagnose - Analyze the current state and identify what's wrong
  2. Explain - Tell the user what happened and why
  3. Fix - Run the necessary commands to fix the migration state
  4. 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 idx values in journal
  • Same migration tag appearing 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:

  1. You branched off main at migration 0008
  2. You added your own migration 0009 (or overwrote 0008)
  3. Meanwhile, upstream added their own 0009
  4. 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 generate asking 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

Step 3: Switch back to feature branch

Read the whole SKILL.md on GitHub

More in Engineering