# Rebase Drizzle Migration

Fix drizzle migrations after rebasing onto upstream/main when migrations diverged

- Repository: https://github.com/humanlayer/humanlayer (12740 stars)
- Category: Engineering
- License: Apache-2.0
- Last updated: 2026-10-31
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add humanlayer/humanlayer --skill rebase-drizzle-migration -g -a claude-code -y`
Codex: `npx skills add humanlayer/humanlayer --skill rebase-drizzle-migration -g -a codex -y`
Cursor: `npx skills add humanlayer/humanlayer --skill rebase-drizzle-migration -g -a cursor -y`
Gemini CLI: `npx skills add humanlayer/humanlayer --skill rebase-drizzle-migration -g -a gemini-cli -y`

## Description

fix drizzle migrations after rebasing onto upstream/main when migrations diverged

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# 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:

```bash
# 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:

```bash
git checkout upstream/main
```

---

### Step 2: Apply migrations to database

Run the migration command:

```bash
bun --bun --cwd packages/db drizzle-kit migrate
```

---

### Step 3: Switch back to feature branch

The rest: https://github.com/humanlayer/humanlayer/blob/HEAD/.claude/skills/rebase-drizzle-migration/SKILL.md
