data-migration-scripts
Create safe, reversible database migration scripts with rollback capabilities, data validation, and zero-downtime deployments. Use when changing database schemas, migrating data between systems, or performing large-scale data transformations.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o data-migration-scripts.zip https://jpskill.com/download/21388.zip && unzip -o data-migration-scripts.zip && rm data-migration-scripts.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/21388.zip -OutFile "$d\data-migration-scripts.zip"; Expand-Archive "$d\data-migration-scripts.zip" -DestinationPath $d -Force; ri "$d\data-migration-scripts.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
data-migration-scripts.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
data-migration-scriptsフォルダができる - 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
- 同梱ファイル
- 8
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
データ移行スクリプト
目次
概要
データベーススキーマの変更やデータ変換に対して、ダウンタイムを最小限に抑えつつ、堅牢で安全かつ元に戻せるデータ移行スクリプトを作成します。
使用場面
- データベーススキーマの変更
- カラムの追加/削除/変更
- データベースシステム間の移行
- データ変換とクリーンアップ
- テーブルの分割または結合
- データ型の変更
- インデックスと制約の追加
- データのバックフィル
- マルチテナントデータ移行
クイックスタート
最小限の動作例:
import { Knex } from "knex";
// migrations/20240101000000_add_user_preferences.ts
export async function up(knex: Knex): Promise<void> {
// Create new table
await knex.schema.createTable("user_preferences", (table) => {
table.uuid("id").primary().defaultTo(knex.raw("gen_random_uuid()"));
table
.uuid("user_id")
.notNullable()
.references("id")
.inTable("users")
.onDelete("CASCADE");
table.jsonb("preferences").defaultTo("{}");
table.timestamp("created_at").defaultTo(knex.fn.now());
table.timestamp("updated_at").defaultTo(knex.fn.now());
table.index("user_id");
});
// Migrate existing data
await knex.raw(`
INSERT INTO user_preferences (user_id, preferences)
SELECT id, jsonb_build_object(
'theme', COALESCE(theme, 'light'),
// ... (see reference guides for full implementation)
リファレンスガイド
references/ ディレクトリにある詳細な実装:
| ガイド | 内容 |
|---|---|
| Knex.js Migrations (Node.js) | Knex.js Migrations (Node.js) |
| Alembic Migrations (Python/SQLAlchemy) | Alembic Migrations (Python/SQLAlchemy) |
| Large Data Migration with Batching | 大規模データ移行とバッチ処理 |
| Zero-Downtime Migration Pattern | ゼロダウンタイム移行パターン |
| Migration Validation | 移行の検証 |
| Cross-Database Migration | クロスデータベース移行 |
ベストプラクティス
✅ 実施すべきこと
- 常に
upとdownの両方の移行を記述する - 本番環境に似たデータで移行をテストする
- アトミックな操作にはトランザクションを使用する
- 大規模なデータセットはバッチで処理する
- データ挿入後にインデックスを追加する
- 移行後にデータを検証する
- 進行状況とエラーをログに記録する
- アプリケーションコードの変更にはフィーチャーフラグを使用する
- 移行を実行する前にデータベースをバックアップする
- ロールバック手順をテストする
- 移行の副作用を文書化する
- すべての移行をバージョン管理する
- べき等な操作を使用する
❌ 実施すべきでないこと
- テストされていない移行を本番環境で実行する
- 後方互換性のない破壊的変更を行う
- 数百万行を単一のトランザクションで処理する
- ロールバックの実装をスキップする
- 移行の失敗を無視する
- 古い移行を変更する
- バックアップなしでデータを削除する
- 本番環境で移行を手動で実行する
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Data Migration Scripts
Table of Contents
Overview
Create robust, safe, and reversible data migration scripts for database schema changes and data transformations with minimal downtime.
When to Use
- Database schema changes
- Adding/removing/modifying columns
- Migrating between database systems
- Data transformations and cleanup
- Splitting or merging tables
- Changing data types
- Adding indexes and constraints
- Backfilling data
- Multi-tenant data migrations
Quick Start
Minimal working example:
import { Knex } from "knex";
// migrations/20240101000000_add_user_preferences.ts
export async function up(knex: Knex): Promise<void> {
// Create new table
await knex.schema.createTable("user_preferences", (table) => {
table.uuid("id").primary().defaultTo(knex.raw("gen_random_uuid()"));
table
.uuid("user_id")
.notNullable()
.references("id")
.inTable("users")
.onDelete("CASCADE");
table.jsonb("preferences").defaultTo("{}");
table.timestamp("created_at").defaultTo(knex.fn.now());
table.timestamp("updated_at").defaultTo(knex.fn.now());
table.index("user_id");
});
// Migrate existing data
await knex.raw(`
INSERT INTO user_preferences (user_id, preferences)
SELECT id, jsonb_build_object(
'theme', COALESCE(theme, 'light'),
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Knex.js Migrations (Node.js) | Knex.js Migrations (Node.js) |
| Alembic Migrations (Python/SQLAlchemy) | Alembic Migrations (Python/SQLAlchemy) |
| Large Data Migration with Batching | Large Data Migration with Batching |
| Zero-Downtime Migration Pattern | Zero-Downtime Migration Pattern |
| Migration Validation | Migration Validation |
| Cross-Database Migration | Cross-Database Migration |
Best Practices
✅ DO
- Always write both
upanddownmigrations - Test migrations on production-like data
- Use transactions for atomic operations
- Process large datasets in batches
- Add indexes after data insertion
- Validate data after migration
- Log progress and errors
- Use feature flags for application code changes
- Back up database before running migrations
- Test rollback procedures
- Document migration side effects
- Version control all migrations
- Use idempotent operations
❌ DON'T
- Run untested migrations on production
- Make breaking changes without backwards compatibility
- Process millions of rows in single transaction
- Skip rollback implementation
- Ignore migration failures
- Modify old migrations
- Delete data without backups
- Run migrations manually in production
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (3,477 bytes)
- 📎 references/alembic-migrations-pythonsqlalchemy.md (2,050 bytes)
- 📎 references/cross-database-migration.md (2,282 bytes)
- 📎 references/knexjs-migrations-nodejs.md (2,532 bytes)
- 📎 references/large-data-migration-with-batching.md (2,929 bytes)
- 📎 references/migration-validation.md (3,044 bytes)
- 📎 references/zero-downtime-migration-pattern.md (1,525 bytes)
- 📎 scripts/validate-schema.sh (426 bytes)