backend-migrations
安全なデータベースマイグレーションの作成
こちらからも入手できます: EIS-ITS
データベースマイグレーションは、誤った方法で実行すると本番アプリケーションを破損させる可能性があります。このスキルは、データを保護し、デプロイリスクを最小限に抑える、可逆的でゼロダウンタイムのマイグレーションを作成するための実証済みのガイドラインを提供します。
スキルZIPをダウンロード
Claudeでアップロード
設定 → 機能 → スキル → スキルをアップロードへ移動
オンにして利用開始
テストする
「backend-migrations」を使用しています。 Create a migration to add a products table with name, price, description, and category_id columns
期待される結果:
- マイグレーションファイルを作成: database/migrations/2024_01_15_000001_create_products_table.php
- 追加されたカラム: name (string), price (decimal), description (text), category_id (unsignedBigInteger)
- 追加されたインデックス: 外部キーパフォーマンスのためcategory_idカラムにインデックスを設定
- タイムスタンプを含む: created_atとupdated_at
- ロールバックメソッド: productsテーブルを完全に削除
「backend-migrations」を使用しています。 Add a new column for user phone numbers to an existing users table
期待される結果:
- マイグレーションファイルを作成: database/migrations/2024_01_15_000002_add_phone_to_users_table.php
- 追加されたカラム: phone_number (string, nullable)
- ゼロダウンタイム技法: まずnullableとしてカラムを追加
- 追加されたインデックス: nullableカラムにはインデックス不要
- ロールバックメソッド: phone_numberカラムを削除
「backend-migrations」を使用しています。 Create an index on the orders table for faster customer lookups
期待される結果:
- マイグレーションファイルを作成: database/migrations/2024_01_15_000003_add_customer_id_index_to_orders.php
- インデックスタイプ: customer_idカラムにB-treeインデックス
- 同時作成: ロックを回避するためCONCURRENTLYオプションを使用
- ロールバックメソッド: customer_id_indexを削除
セキュリティ監査
安全All 24 static findings are FALSE POSITIVES. These are documentation/metadata files with no executable code. The detected patterns are text in documentation (URLs, file paths, code formatting backticks, security terminology) that trigger pattern matching but pose no actual security risk. The embedded security audit in skill-report.json confirms this skill is safe.
リスク要因
🌐 ネットワークアクセス (1)
📁 ファイルシステムへのアクセス (4)
⚙️ 外部コマンド (1)
品質スコア
作れるもの
安全なマイグレーションパターン
本番環境でデータ損失なく安全にロールバックできるマイグレーションを作成
ゼロダウンタイムデプロイ
サービス中断なく継続的なデプロイを可能にするデータベース変更の計画
マイグレーション標準
バージョン管理ガイドラインを用いて、開発チーム全体で一貫したマイグレーションプラクティスを確立
これらのプロンプトを試す
Create a new migration file to add a users table with name, email, password, and timestamps columns. Include proper indexes and make it reversible.
Add a new column to the orders table in production. Use proper zero-downtime technique. Include rollback logic.
Create an index on the orders table for the customer_id column. Use concurrent index creation to avoid locking.
Modify the orders.total column from decimal to integer. Ensure backward compatibility and include rollback method.
ベストプラクティス
- マイグレーションを完全に元に戻せるdown()メソッドを常に含める
- 大規模テーブルではロックを防ぐため同時インデックス作成を使用
- より安全なデプロイのためスキーマ変更とデータマイグレーションを分離
- デプロイ前に本番環境に近いデータでマイグレーションをテスト
回避
- 本番環境にデプロイ済みの既存マイグレーションを変更する
- データベースエンジンの特性を考慮せずに生SQLを使用する
- down()メソッドをスキップしたり不完全にしたりする
- テーブルサイズとロック時間を考慮せずにインデックスを作成する