本文へ移動
cccskills
無料GitHub で公開日本語紹介

rebase-drizzle-migration

リベース後に競合したDrizzleのマイグレーションを診断し、履歴やスナップショットを整理して、スキーマ変更の再生成と適用後の検証を進めるスキル。

原文原文の説明を見る

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

実行スコア 未検証

インストール方法を見る

こんなときに便利

  • リベース後の競合を修復したいとき
  • マイグレーション履歴の重複整理
  • 意図したスキーマ変更の再生成
  • 不自然なカラム名変更の質問の調査

日本語での紹介

できること

リベース後に食い違ったDrizzleのマイグレーションを、診断から修復、検証まで順に進めます。マイグレーションは、データベースの構造変更を順番に適用する仕組みです。SQLファイル、履歴を記録する_journal.json、構造を保存したスナップショットを照合し、番号やタグの重複、意図しないスキーマの差分を調べます。上流の履歴に合わせて整理した後、必要な変更を新しいマイグレーションとして生成し直します。

こんなときに便利

自分のブランチとupstream/mainで同じ番号の変更が追加された場合や、生成時に不自然なカラム名変更の質問が出る場合に向いています。修復後は差分、型チェック、テストで結果を確認します。

使い方の例

  • 「リベース後にDrizzleの履歴が重複したので、状態を診断して修復して」
  • 「意図したスキーマ変更だけでマイグレーションを生成し直して」

注意点

Git、Bun、drizzle-kitと、原文のディレクトリ構成を前提にした手順です。Docker ComposeでローカルDBを初期化する工程は全データを削除するため、利用者に依頼し、明示的に頼まれた場合だけエージェントが実行する指定があります。

この紹介文は、公開されている SKILL.md をもとに AI(OpenAI Codex)が作成しました。正確な仕様は下の原文を確認してください。

含まれるファイル(1)

  • SKILL.md5.7 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

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

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

同じリポジトリのスキル

agent-browser

無料概要あり

Webページの移動やフォーム入力、クリックをエージェントに任せ、情報抽出や画面保存、操作前後の比較まで行います。ブラウザ作業の自動化やWebアプリの確認に使えるスキル。

  • フォーム入力やクリックを自動化したいとき
  • Webページのテキスト抽出
  • ページのスクリーンショット・PDF保存
humanlayer/humanlayer1.2万2026年10月23日 更新

asd-ste100

無料概要あり

曖昧で読みにくい英文を、語の意味をそろえた短い能動態の文へ書き直すスキル。指示文やツール説明を見直し、修正理由と変更前後を表で確認できます。

  • 別のエージェントへの英文指示の明確化
  • 英語のツール説明やエラー文の簡素化
  • 英語を母語としない読者向けの文章整理
humanlayer/humanlayer1.2万2026年10月23日 更新

better-github-skill

無料概要あり

GitHubのPRの状態、レビューの会話、CI失敗のログを専用スクリプトで収集し、変更の確認状況や未解決の指摘、失敗したジョブとステップを調べるスキル。

  • PRの状態をまとめて確認したいとき
  • 未解決のレビューの会話の確認
  • CIの失敗ジョブとステップの調査
humanlayer/humanlayer1.2万2026年10月23日 更新

bump-version

無料概要あり

リリース時に対象パッケージの基準バージョンを更新し、関連ファイルの同期と生成結果を検証して、コミットからPRブランチへのプッシュまで進めるスキル。

  • リリース用のバージョンを更新したいとき
  • 関連ファイルのバージョン表記の同期
  • プッシュ前の生成バージョン検証
humanlayer/humanlayer1.2万2026年10月23日 更新

calldiff

無料概要あり

Git のコミット間や作業中のコードで、関数の呼び出し構造の違いを確認します。呼び出しツリーの表示や、指定した関数へ至る経路の調査にも使えます。

  • 変更前後の関数呼び出しを比較したいとき
  • ブランチ間の呼び出し構造レビュー
  • 起点から目的の関数への経路調査
humanlayer/humanlayer1.2万2026年10月23日 更新

chrome-devtools-cli

無料概要あり

ターミナルからブラウザのクリックや入力、ページ移動を自動化し、通信やエラー、表示速度も調べられる、Chrome DevToolsのCLI操作を支援するスキル。

  • フォーム入力やページ移動の自動化
  • ページや要素の画面撮影
  • 通信内容やコンソールエラーの調査
humanlayer/humanlayer1.2万2026年10月23日 更新

humanlayer のスキルをすべて見る

このスキルの問題を報告する