database-migration-helper
Creates database migration files following project conventions for Prisma, Sequelize, Alembic, Knex, TypeORM, and other ORMs. Use when adding tables, modifying schemas, or when user mentions database changes.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o database-migration-helper.zip https://jpskill.com/download/18104.zip && unzip -o database-migration-helper.zip && rm database-migration-helper.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/18104.zip -OutFile "$d\database-migration-helper.zip"; Expand-Archive "$d\database-migration-helper.zip" -DestinationPath $d -Force; ri "$d\database-migration-helper.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
database-migration-helper.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
database-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
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
データベースマイグレーションヘルパー
このスキルは、プロジェクトのORM規約と命名パターンに従ったデータベースマイグレーションファイルを作成するのに役立ちます。
このスキルの使用時
- ユーザーがデータベースマイグレーションの作成を要求した場合
- データベースに新しいテーブルまたはカラムを追加する場合
- 既存のデータベーススキーマを変更する場合
- インデックス、制約、またはリレーションシップを作成する場合
- ユーザーが「migration」、「schema change」、または「database update」に言及した場合
指示
1. ORM/マイグレーションツールの検出
まず、プロジェクトで使用されているORMまたはマイグレーションツールを特定します。
- Prisma:
prisma/schema.prismaまたは package.json 内の@prisma/clientを探します。 - Sequelize:
.sequelizercまたは package.json 内のsequelize-cliを探します。 - Knex:
knexfile.jsまたは package.json 内のknexを探します。 - TypeORM:
ormconfig.jsonまたは package.json 内のtypeormを探します。 - Alembic (Python):
alembic.iniまたはalembic/ディレクトリを探します。 - Django:
manage.pyおよび*/migrations/内の Django マイグレーションを探します。 - Active Record (Rails):
db/migrate/ディレクトリを探します。 - Flyway:
flyway.confまたはdb/migration/を探します。 - Liquibase:
liquibase.propertiesまたはチェンジログファイルを探します。
Glob を使用して、これらの指標ファイルを検索します。
2. 既存のマイグレーションの調査
既存のマイグレーションファイルを読み込んで、以下を理解します。
- 命名規約 (タイムスタンプ形式、説明形式)
- ディレクトリ構造
- マイグレーションファイル形式 (SQL, JavaScript, TypeScript, Python など)
- コーディングパターン (up/down 関数、forwards/rollback など)
Grep を使用して、最近のマイグレーションを検索します。以下の共通ディレクトリを調べます。
prisma/migrations/db/migrate/migrations/またはdatabase/migrations/alembic/versions/
3. マイグレーションファイルの生成
検出されたORMに基づいて、適切なマイグレーションファイルを作成します。
Prisma
npx prisma migrate dev --name <description>を実行します。またはprisma/migrations/<timestamp>_<name>/migration.sqlにマイグレーション SQL を手動で作成します。
Sequelize
- 生成:
npx sequelize-cli migration:generate --name <description> - 次に、up/down 関数にスキーマの変更を記述します。
Knex
- 生成:
npx knex migrate:make <description> - exports.up および exports.down 関数に記述します。
TypeORM
- 生成:
npm run typeorm migration:create src/migrations/<Name> - up() および down() メソッドを実装します。
Alembic
- 生成:
alembic revision -m "<description>" - upgrade() および downgrade() 関数に記述します。
Django
- 実行:
python manage.py makemigrations - または、
<app>/migrations/にマイグレーションを手動で作成します。
Rails
- 生成:
rails generate migration <ClassName> - change メソッド (または複雑なマイグレーションの場合は up/down) に記述します。
4. 命名規約に従う
一貫性のある、説明的な名前を使用します。
- 良い例:
add_user_email_index,create_products_table,add_payment_status_to_orders - 悪い例:
migration1,update,fix
プロジェクトのパターンに基づいてフォーマットします。
- タイムスタンププレフィックス:
20231215120000_add_email_to_users - 連番:
001_create_users,002_add_indexes
5. Up と Down/Rollback の両方を含める
サポートされている場合は、常に両方向を提供します。
- Up/Upgrade/Forward: スキーマの変更を適用します。
- Down/Downgrade/Rollback: スキーマの変更を元に戻します。
可逆的な操作を使用するORM (Rails、一部のSequelize) の場合、単一の change メソッドで十分な場合があります。
6. マイグレーションコンテンツのガイドライン
テーブルの作成:
- 適切な型ですべてのカラムを定義します。
- 適切な場合は NOT NULL 制約を設定します。
- プライマリキーを追加します。
- プロジェクトで使用している場合は、タイムスタンプ (created_at, updated_at) を含めます。
- プロジェクトが好む場合は、同じマイグレーションまたは別のマイグレーションで外部キーとインデックスを追加します。
テーブルの変更:
- 具体的に:
ADD COLUMN,DROP COLUMN,MODIFY COLUMN - 既存のデータを適切に処理します (デフォルト値、バックフィル)。
- 後方互換性を考慮します。
インデックスの追加:
- インデックスに明確な名前を付けます:
idx_users_email,idx_orders_user_id_created_at - 適切なインデックスタイプを使用します (B-tree, Hash, GIN など)。
- 大規模なテーブルの場合は、部分インデックスを検討します。
データマイグレーション:
- 可能であれば、スキーママイグレーションとデータマイグレーションを分離します。
- 大量のデータセットには注意してください (バッチ処理)。
- 現実的なデータ量でロールバックをテストします。
7. マイグレーションの安全性の検証
確定する前に、以下を確認してください。
- 可逆性: マイグレーションをロールバックできますか?
- データ損失: データが失われることはありませんか? ユーザーに警告してください!
- ダウンタイム: これによりテーブルがロックされますか? 大規模なテーブルの場合は、オンラインマイグレーションを検討してください。
- 依存関係: 最初に実行する必要がある依存マイグレーションはありますか?
8. テストの推奨事項
ユーザーに以下を提案します。
- 最初に開発データベースでマイグレーションを実行します。
- ロールバック機能をテストします。
- 本番環境の場合: ステージング環境でテストします。
- 生成されたSQLを確認します (自動生成するORMの場合)。
ORM固有のテンプレート
templates/ ディレクトリのテンプレートを参照してください。
prisma-migration.sql- Prisma マイグレーションの例sequelize-migration.js- Sequelize マイグレーションの例knex-migration.js- Knex マイグレーションの例typeorm-migration.ts- TypeORM マイグレーションの例alembic-migration.py- Alembic マイグレーションの例rails-migration.rb- Rails マイグレーションの例
ベストプラクティス
- マイグレーションごとに1つの目的: 関係のない変更を混在させないでください。
- 説明的な名前: 名前はマイグレーションの内容を説明する必要があります。
- タイムスタンプ: 順序付けのためにORMのタイムスタンプ形式を使用します。
- 可能な場合は冪等: 複数回実行しても安全です。
- ロールバックのテスト: down/rollback が正しく動作することを確認します。
- 複雑なロジックのドキュメント化: 自明でない操作にはコメントを追加します。
- 大規模な操作のバッチ処理: 多数の行に影響を与えるデータマイグレーションの場合。
- トランザクションの使用: サポートされている場合は、トランザクションで操作をラップします。
サポートファイル
templates/: さまざまなORMのマイグレーションテンプレートreference.md: 命名規約とマイグレーションパターン
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Database Migration Helper
This skill helps you create database migration files that follow your project's ORM conventions and naming patterns.
When to Use This Skill
- User requests to create a database migration
- Adding new tables or columns to the database
- Modifying existing database schema
- Creating indexes, constraints, or relationships
- User mentions "migration", "schema change", or "database update"
Instructions
1. Detect the ORM/Migration Tool
First, identify which ORM or migration tool the project uses:
- Prisma: Look for
prisma/schema.prismaor@prisma/clientin package.json - Sequelize: Look for
.sequelizercorsequelize-cliin package.json - Knex: Look for
knexfile.jsorknexin package.json - TypeORM: Look for
ormconfig.jsonortypeormin package.json - Alembic (Python): Look for
alembic.inioralembic/directory - Django: Look for
manage.pyand Django migrations in*/migrations/ - Active Record (Rails): Look for
db/migrate/directory - Flyway: Look for
flyway.confordb/migration/ - Liquibase: Look for
liquibase.propertiesor changelog files
Use Glob to search for these indicator files.
2. Examine Existing Migrations
Read existing migration files to understand:
- Naming conventions (timestamp format, description format)
- Directory structure
- Migration file format (SQL, JavaScript, TypeScript, Python, etc.)
- Coding patterns (up/down functions, forwards/rollback, etc.)
Use Grep to find recent migrations: look in common directories like:
prisma/migrations/db/migrate/migrations/ordatabase/migrations/alembic/versions/
3. Generate Migration File
Based on the detected ORM, create an appropriate migration file:
Prisma
- Run
npx prisma migrate dev --name <description>OR - Manually create migration SQL in
prisma/migrations/<timestamp>_<name>/migration.sql
Sequelize
- Generate:
npx sequelize-cli migration:generate --name <description> - Then fill in the up/down functions with the schema changes
Knex
- Generate:
npx knex migrate:make <description> - Fill in exports.up and exports.down functions
TypeORM
- Generate:
npm run typeorm migration:create src/migrations/<Name> - Implement up() and down() methods
Alembic
- Generate:
alembic revision -m "<description>" - Fill in upgrade() and downgrade() functions
Django
- Run:
python manage.py makemigrations - Or manually create migration in
<app>/migrations/
Rails
- Generate:
rails generate migration <ClassName> - Fill in the change method (or up/down for complex migrations)
4. Follow Naming Conventions
Use consistent, descriptive names:
- Good:
add_user_email_index,create_products_table,add_payment_status_to_orders - Bad:
migration1,update,fix
Format based on project patterns:
- Timestamp prefix:
20231215120000_add_email_to_users - Sequential:
001_create_users,002_add_indexes
5. Include Both Up and Down/Rollback
Always provide both directions when supported:
- Up/Upgrade/Forward: Apply the schema change
- Down/Downgrade/Rollback: Revert the schema change
For ORMs that use reversible operations (Rails, some Sequelize), a single change method may be sufficient.
6. Migration Content Guidelines
Creating Tables:
- Define all columns with appropriate types
- Set NOT NULL constraints where appropriate
- Add primary keys
- Include timestamps (created_at, updated_at) if project uses them
- Add foreign keys and indexes in the same migration or separate if project prefers
Altering Tables:
- Be specific:
ADD COLUMN,DROP COLUMN,MODIFY COLUMN - Handle existing data appropriately (defaults, backfills)
- Consider backwards compatibility
Adding Indexes:
- Name indexes clearly:
idx_users_email,idx_orders_user_id_created_at - Use appropriate index types (B-tree, Hash, GIN, etc.)
- Consider partial indexes for large tables
Data Migrations:
- Separate schema migrations from data migrations if possible
- Be cautious with large datasets (batch operations)
- Test rollback with realistic data volumes
7. Validate Migration Safety
Before finalizing, check:
- Reversibility: Can the migration be rolled back?
- Data loss: Will any data be lost? Warn the user!
- Downtime: Will this lock tables? Consider online migrations for large tables
- Dependencies: Are there dependent migrations that must run first?
8. Testing Recommendations
Suggest to the user:
- Run migration on a development database first
- Test rollback functionality
- For production: test on a staging environment
- Review generated SQL (for ORMs that auto-generate)
ORM-Specific Templates
Reference the templates in templates/ directory:
prisma-migration.sql- Prisma migration examplesequelize-migration.js- Sequelize migration exampleknex-migration.js- Knex migration exampletypeorm-migration.ts- TypeORM migration examplealembic-migration.py- Alembic migration examplerails-migration.rb- Rails migration example
Best Practices
- One purpose per migration: Don't mix unrelated changes
- Descriptive names: Names should explain what the migration does
- Timestamps: Use the ORM's timestamp format for ordering
- Idempotent when possible: Safe to run multiple times
- Test rollbacks: Ensure down/rollback works correctly
- Document complex logic: Add comments for non-obvious operations
- Batch large operations: For data migrations affecting many rows
- Use transactions: Wrap operations in transactions when supported
Supporting Files
templates/: Migration templates for various ORMsreference.md: Naming conventions and migration patterns