Skip to content
cccskills
FreePublished on GitHub

rebase-drizzle-migration

Repair conflicting Drizzle migrations after a rebase by inspecting migration history, SQL files, and schema snapshots. The skill guides cleanup, regeneration of database change scripts, local application, and verification against the upstream branch.

OriginalShow the original description

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

Run score Not tested

See how to install

Good for

  • Repairing conflicting migrations after a rebase
  • Removing duplicate migration history entries
  • Regenerating migrations for intended schema changes
  • Investigating unexpected column rename prompts

Files included (1)

  • SKILL.md5.7 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

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

Switch back to the feature branch:

git checkout <branch-name>

Step 4: Clean up migration artifacts

Run cleanup commands:

# Identify what needs cleanup by checking diff
git diff upstream/main --stat -- packages/db/drizzle/

# Check current journal state
cat packages/db/drizzle/meta/_journal.json | tail -20

Then perform cleanup:

  • Remove migration SQL files the branch added: rm packages/db/drizzle/0010_*.sql
  • Remove corresponding snapshots: rm packages/db/drizzle/meta/0010_snapshot.json
  • Restore journal from upstream: git checkout upstream/main -- packages/db/drizzle/meta/_journal.json
  • Restore any accidentally modified snapshots: git checkout upstream/main -- packages/db/drizzle/meta/0009_snapshot.json
  • Restore schema files that should match upstream (files user didn't intentionally modify)

Step 5: Verify clean state

Run verification:

git diff upstream/main --stat -- packages/db/

The diff should now show ONLY schema file changes (e.g., sessions.ts), not migration files.


Step 6: reseet database state

Ask the user (DO NOT DO THIS YOURSELF UNLESS YOU ARE ASKED TO DO SO) to reset the database state to the upstream/main state.

# reset the database volumes
docker compose down -v && docker compose up -d

# then seed the existing migrations
bun --bun --cwd packages/db drizzle-kit migrate

This will delete all data in the local database and re-apply the upstream migrations.


Step 7: Regenerate migration

Generate a fresh migration for the schema changes:

bun run db:migrations:generate

This should create a new migration file (e.g., 0010_something.sql) with just the changes.


Step 8: Apply migration locally

Apply the new migration to the local database:

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

Step 9: Verify and commit

After migration succeeds, verify:

# Check the final diff
git diff upstream/main --stat -- packages/db/

# Run typecheck
bun run typecheck

# Run tests
bun --bun run test

The diff should show:

  • The new migration SQL file
  • The new snapshot JSON
  • Updated journal
  • Schema file changes

Troubleshooting

If drizzle-kit asks about column renames during generate

The schema doesn't match what drizzle expects. Check if:

  • Schema files were accidentally reverted during rebase
  • Upstream renamed columns that your schema still has with old names

Fix: git checkout upstream/main -- packages/db/src/tables/<file>.ts for files you didn't intend to modify.

If journal still has duplicates after cleanup

The checkout didn't work or there are staged changes. Run:

git checkout upstream/main -- packages/db/drizzle/meta/_journal.json

If local DB is in weird state

Run migrate on upstream/main again, then switch back to branch.

Key Files Reference

  • packages/db/drizzle/*.sql - Migration SQL files (sequential: 0000, 0001, ...)
  • packages/db/drizzle/meta/_journal.json - Tracks all migrations and their order
  • packages/db/drizzle/meta/NNNN_snapshot.json - Schema snapshot after each migration
  • packages/db/src/tables/*.ts - Drizzle schema definitions

Commands Reference (for agent)

# All commands are non-interactive and safe for agent to run:
git diff upstream/main --stat -- packages/db/
git show upstream/main:packages/db/drizzle/meta/_journal.json
cat packages/db/drizzle/meta/_journal.json
ls packages/db/drizzle/*.sql
git checkout upstream/main -- <file>  # restore specific file
rm packages/db/drizzle/0010_*.sql     # cleanup
bun run db:migrations:generate
bun --bun --cwd packages/db drizzle-kit migrate

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

agent-browser

FreeSummary

Automate website navigation, form entry, and clicks through a browser command line tool. Extract page text, capture screenshots, and compare page states to check interactions or test web app behavior across screen sizes.

  • Automate form entry and button clicks
  • Extract text from web pages
  • Save page screenshots and PDFs
humanlayer/humanlayer12.1KUpdated Oct 23, 2026

asd-ste100

FreeSummary

Rewrite dense or ambiguous English into short, direct sentences using principles from ASD-STE100, a standard for clear technical English. It preserves facts and conditions, identifies writing issues, and shows the original and revised text side by side.

  • Clarifying English instructions for another agent
  • Simplifying English tool descriptions and error messages
  • Making English easier for non-native readers
humanlayer/humanlayer12.1KUpdated Oct 23, 2026

Inspect GitHub pull requests, read review conversations, and investigate failed automated checks with dedicated scripts. Get consolidated status reports, unresolved discussion threads, and failing job or step logs, with full logs saved for further inspection.

  • Checking pull request status in one report
  • Reading unresolved review conversations
  • Investigating failed CI jobs and steps
humanlayer/humanlayer12.1KUpdated Oct 23, 2026

bump-version

FreeSummary

Update release base versions for supported packages, keep matching version fields in sync, and verify generated versions. The workflow covers committing and pushing the changes, with guidance for release steps after merging.

  • Prepare a package version update for release
  • Synchronize version fields across related files
  • Verify generated versions before pushing
humanlayer/humanlayer12.1KUpdated Oct 23, 2026

calldiff

FreeSummary

Compare function call structures across Git commits, branches, or working files to support code review. Display call trees and trace paths from an entry function to a target function, with support for 22 languages.

  • Compare function calls before and after a change
  • Review call structure changes between branches
  • Trace paths from an entry function to a target
humanlayer/humanlayer12.1KUpdated Oct 23, 2026

Automate browser tasks from the terminal using the chrome-devtools-mcp CLI. Inspect page elements, click and fill forms, navigate tabs, capture screenshots, and investigate network requests, console messages, performance, and memory through shell commands.

  • Automating form input and page navigation
  • Capturing page or element screenshots
  • Investigating network requests and console errors
humanlayer/humanlayer12.1KUpdated Oct 23, 2026

See all skills by humanlayer

Report a problem with this skill