convex-migration-helper
Convexのスキーマやデータ移行を安全に進めるために、スキーマの拡張、移行、縮小という手順で、データのバックフィルや型変更、テーブル分割などを、ダウンタイムなしで実行するSkill。
📜 元の英語説明(参考)
Plans and executes safe Convex schema and data migrations using the widen-migrate-narrow workflow and the @convex-dev/migrations component. Use this skill when a deployment fails schema validation, existing documents need backfilling, fields need adding or removing or changing type, tables need splitting or merging, or a zero-downtime migration strategy is needed. Also use when the user mentions breaking schema changes, multi-deploy rollouts, or data transformations on existing Convex tables.
🇯🇵 日本人クリエイター向け解説
Convexのスキーマやデータ移行を安全に進めるために、スキーマの拡張、移行、縮小という手順で、データのバックフィルや型変更、テーブル分割などを、ダウンタイムなしで実行するSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o convex-migration-helper.zip https://jpskill.com/download/19142.zip && unzip -o convex-migration-helper.zip && rm convex-migration-helper.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/19142.zip -OutFile "$d\convex-migration-helper.zip"; Expand-Archive "$d\convex-migration-helper.zip" -DestinationPath $d -Force; ri "$d\convex-migration-helper.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
convex-migration-helper.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
convex-migration-helperフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 4
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
Convex Migration Helper
破壊的な変更を行う際に、Convex のスキーマとデータを安全に移行します。
使用するタイミング
- 既存のテーブルに新しい必須フィールドを追加する場合
- フィールドの型や構造を変更する場合
- テーブルを分割または結合する場合
- フィールドの名前を変更または削除する場合
- ネストされたデータからリレーショナルデータに移行する場合
使用しないタイミング
- 本番環境または開発環境に既存のデータがない、グリーンフィールドのスキーマの場合
- バックフィルが不要なオプションフィールドを追加する場合
- 移行する既存のデータがない新しいテーブルを追加する場合
- 正確性の懸念がないインデックスを追加または削除する場合
- 移行の必要がない Convex スキーマ設計に関する質問の場合
主要な概念
スキーマ検証がワークフローを推進する
Convex は、保存されているデータと一致しないスキーマのデプロイを許可しません。これは、すべての移行を形成する基本的な制約です。
- 既存のドキュメントに必須フィールドがない場合、そのフィールドを追加することはできません
- 既存のドキュメントが古い型を持っている場合、フィールドの型を変更することはできません
- 既存のドキュメントにまだフィールドがある場合、スキーマからそのフィールドを削除することはできません
これは、移行が予測可能なパターンに従うことを意味します。スキーマを広げ、データを移行し、スキーマを狭めます。
オンライン移行
Convex の移行はオンラインで実行されます。つまり、データが非同期にバッチで更新されている間も、アプリはリクエストを処理し続けます。移行期間中、コードは古いデータ形式と新しいデータ形式の両方を処理する必要があります。
型の変更よりも新しいフィールドを優先する
データの形状を変更する場合、既存のフィールドを変更するのではなく、新しいフィールドを作成してください。これにより、移行がより安全になり、ロールバックが容易になります。
データを削除しない
確信がない限り、フィールドを削除するよりも非推奨にすることを優先してください。フィールドを v.optional としてマークし、非推奨になった理由と存在した理由を説明するコードコメントを追加してください。
安全な変更(移行不要)
オプションフィールドの追加
// Before
users: defineTable({
name: v.string(),
})
// After - safe, new field is optional
users: defineTable({
name: v.string(),
bio: v.optional(v.string()),
})
新しいテーブルの追加
posts: defineTable({
userId: v.id("users"),
title: v.string(),
}).index("by_user", ["userId"])
インデックスの追加
users: defineTable({
name: v.string(),
email: v.string(),
})
.index("by_email", ["email"])
破壊的な変更:デプロイワークフロー
すべての破壊的な移行は、同じ複数デプロイパターンに従います。
デプロイ 1 - スキーマを広げる:
- 古い形式と新しい形式の両方を許可するようにスキーマを更新します(例:オプションの新しいフィールドを追加)
- 読み取り時に両方の形式を処理するようにコードを更新します
- 新しいドキュメントに対して新しい形式を書き込むようにコードを更新します
- デプロイします
デプロイ間 - データを移行する:
- 既存のドキュメントをバックフィルするために移行を実行します
- すべてのドキュメントが移行されたことを確認します
デプロイ 2 - スキーマを狭める:
- 新しい形式のみを要求するようにスキーマを更新します
- 古い形式を処理するコードを削除します
- デプロイします
Migrations コンポーネントの使用
些細ではない移行には、@convex-dev/migrations コンポーネントを使用してください。これは、バッチ処理、カーソルベースのページネーション、状態追跡、障害からの再開、ドライラン、および進捗監視を処理します。
インストール、セットアップ、移行の定義と実行、ドライラン、ステータス監視、および設定オプションについては、references/migrations-component.md を参照してください。
一般的な移行パターン
コード例を含む完全なパターンについては、references/migration-patterns.md を参照してください。
- 必須フィールドの追加
- フィールドの削除
- フィールド型の変更
- ネストされたデータを別のテーブルに分割する
- 孤立したドキュメントのクリーンアップ
- ゼロダウンタイム戦略(デュアルライト、デュアルリード)
- 小規模テーブルのショートカット(コンポーネントなしの単一の internalMutation)
- 移行が完了したことの検証
一般的な落とし穴
- データを移行する前にフィールドを必須にする: 既存のドキュメントにフィールドがないため、Convex はデプロイを拒否します。常に最初にスキーマを広げてください。
- 大規模なテーブルで
.collect()を使用する: トランザクション制限に達したり、タイムアウトを引き起こしたりします。適切なバッチページネーションには migrations コンポーネントを使用してください。.collect()は、小さいことがわかっているテーブルでのみ安全です。 - 移行する前に新しい形式を書き込まない: 移行期間中に作成されたドキュメントは見落とされ、移行が「完了」した後も未移行のデータが残ります。
- ドライランをスキップする:
dryRun: trueを使用して、本番データに変更をコミットする前に移行ロジックを検証してください。実際のドキュメントに触れる前にバグを検出します。 - フィールドを時期尚早に削除する:
v.optionalとコメントで非推奨にすることを優先してください。データが不要になり、コードが参照しなくなったことを確信してからのみ削除してください。 - 移行バッチに cron を使用する: migrations コンポーネントは、内部で再帰的なスケジューリングによってバッチ処理を処理します。cron は手動でのクリーンアップと、削除するための追加のデプロイが必要です。
移行チェックリスト
- [ ] 破壊的な変更を特定し、複数デプロイワークフローを計画する
- [ ] 古い形式と新しい形式の両方を許可するようにスキーマを更新する
- [ ] 読み取り時に両方の形式を処理するようにコードを更新する
- [ ] 新しいドキュメントに対して新しい形式を書き込むようにコードを更新する
- [ ] 広げられたスキーマと更新されたコードをデプロイする
- [ ]
@convex-dev/migrationsコンポーネントを使用して移行を定義する - [ ]
dryRun: trueでテストする - [ ] 移行を実行し、ステータスを監視する
- [ ] すべてのドキュメントが移行されたことを確認する
- [ ] 新しい形式のみを要求するようにスキーマを更新する
- [ ] 古い形式を処理していたコードをクリーンアップする
- [ ] 最終的なスキーマとコードをデプロイする
- [ ] 安定していることを確認したら移行コードを削除する
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Convex Migration Helper
Safely migrate Convex schemas and data when making breaking changes.
When to Use
- Adding new required fields to existing tables
- Changing field types or structure
- Splitting or merging tables
- Renaming or deleting fields
- Migrating from nested to relational data
When Not to Use
- Greenfield schema with no existing data in production or dev
- Adding optional fields that do not need backfilling
- Adding new tables with no existing data to migrate
- Adding or removing indexes with no correctness concern
- Questions about Convex schema design without a migration need
Key Concepts
Schema Validation Drives the Workflow
Convex will not let you deploy a schema that does not match the data at rest. This is the fundamental constraint that shapes every migration:
- You cannot add a required field if existing documents don't have it
- You cannot change a field's type if existing documents have the old type
- You cannot remove a field from the schema if existing documents still have it
This means migrations follow a predictable pattern: widen the schema, migrate the data, narrow the schema.
Online Migrations
Convex migrations run online, meaning the app continues serving requests while data is updated asynchronously in batches. During the migration window, your code must handle both old and new data formats.
Prefer New Fields Over Changing Types
When changing the shape of data, create a new field rather than modifying an existing one. This makes the transition safer and easier to roll back.
Don't Delete Data
Unless you are certain, prefer deprecating fields over deleting them. Mark the field as v.optional and add a code comment explaining it is deprecated and why it existed.
Safe Changes (No Migration Needed)
Adding Optional Field
// Before
users: defineTable({
name: v.string(),
})
// After - safe, new field is optional
users: defineTable({
name: v.string(),
bio: v.optional(v.string()),
})
Adding New Table
posts: defineTable({
userId: v.id("users"),
title: v.string(),
}).index("by_user", ["userId"])
Adding Index
users: defineTable({
name: v.string(),
email: v.string(),
})
.index("by_email", ["email"])
Breaking Changes: The Deployment Workflow
Every breaking migration follows the same multi-deploy pattern:
Deploy 1 - Widen the schema:
- Update schema to allow both old and new formats (e.g., add optional new field)
- Update code to handle both formats when reading
- Update code to write the new format for new documents
- Deploy
Between deploys - Migrate data:
- Run migration to backfill existing documents
- Verify all documents are migrated
Deploy 2 - Narrow the schema:
- Update schema to require the new format only
- Remove code that handles the old format
- Deploy
Using the Migrations Component
For any non-trivial migration, use the @convex-dev/migrations component. It handles batching, cursor-based pagination, state tracking, resume from failure, dry runs, and progress monitoring.
See references/migrations-component.md for installation, setup, defining and running migrations, dry runs, status monitoring, and configuration options.
Common Migration Patterns
See references/migration-patterns.md for complete patterns with code examples covering:
- Adding a required field
- Deleting a field
- Changing a field type
- Splitting nested data into a separate table
- Cleaning up orphaned documents
- Zero-downtime strategies (dual write, dual read)
- Small table shortcut (single internalMutation without the component)
- Verifying a migration is complete
Common Pitfalls
- Making a field required before migrating data: Convex rejects the deploy because existing documents lack the field. Always widen the schema first.
- Using
.collect()on large tables: Hits transaction limits or causes timeouts. Use the migrations component for proper batched pagination..collect()is only safe for tables you know are small. - Not writing the new format before migrating: Documents created during the migration window will be missed, leaving unmigrated data after the migration "completes."
- Skipping the dry run: Use
dryRun: trueto validate migration logic before committing changes to production data. Catches bugs before they touch real documents. - Deleting fields prematurely: Prefer deprecating with
v.optionaland a comment. Only delete after you are confident the data is no longer needed and no code references it. - Using crons for migration batches: The migrations component handles batching via recursive scheduling internally. Crons require manual cleanup and an extra deploy to remove.
Migration Checklist
- [ ] Identify the breaking change and plan the multi-deploy workflow
- [ ] Update schema to allow both old and new formats
- [ ] Update code to handle both formats when reading
- [ ] Update code to write the new format for new documents
- [ ] Deploy widened schema and updated code
- [ ] Define migration using the
@convex-dev/migrationscomponent - [ ] Test with
dryRun: true - [ ] Run migration and monitor status
- [ ] Verify all documents are migrated
- [ ] Update schema to require new format only
- [ ] Clean up code that handled old format
- [ ] Deploy final schema and code
- [ ] Remove migration code once confirmed stable
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (6,056 bytes)
- 📎 assets/icon.svg (386 bytes)
- 📎 references/migration-patterns.md (6,186 bytes)
- 📎 references/migrations-component.md (4,128 bytes)