database-migration-generator

majiayu000's avatarfrom majiayu000

Generate database migration scripts with rollback support for various databases. Use when creating schema migrations or database changes.

⭐5stars🔀1forks📁View on GitHub🕐Updated Jan 11, 2026

When & Why to Use This Skill

This Claude skill automates the generation of comprehensive database migration scripts with built-in rollback support. It streamlines schema management by producing both 'up' (schema changes) and 'down' (reversal) scripts for various environments, including raw SQL and TypeORM. By ensuring consistent versioning and providing ready-to-use templates for tables, indexes, and foreign keys, it helps developers maintain data integrity and accelerate the backend development lifecycle.

Use Cases

  • Initial Schema Setup: Rapidly generating the foundational SQL scripts for new projects, including tables, primary keys, and initial constraints.
  • Safe Schema Evolution: Creating ALTER TABLE scripts for adding or removing columns in existing databases, complete with rollback logic to ensure system stability during deployments.
  • ORM Integration: Generating TypeScript-based migration files for TypeORM to maintain synchronization between the application's data models and the physical database schema.
  • Database Index Optimization: Automatically drafting CREATE INDEX scripts to improve query performance without manually writing complex syntax.
namedatabase-migration-generator
descriptionGenerate database migration scripts with rollback support for various databases. Use when creating schema migrations or database changes.

Database Migration Generator Skill

データベースマイグレーションスクリプトを生成するスキルです。

主な機能

  • テーブル作成: CREATE TABLE
  • カラム追加/削除: ALTER TABLE
  • インデックス: CREATE INDEX
  • 外部キー: FOREIGN KEY制約
  • ロールバック: DOWN migration

生成例

-- migrations/001_create_users.up.sql
CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    email VARCHAR(255) NOT NULL UNIQUE,
    name VARCHAR(100) NOT NULL,
    password_hash VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX idx_users_email ON users(email);

-- migrations/001_create_users.down.sql
DROP TABLE IF EXISTS users;

TypeORM (TypeScript)

import { MigrationInterface, QueryRunner, Table } from 'typeorm';

export class CreateUsers1234567890 implements MigrationInterface {
    async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.createTable(new Table({
            name: 'users',
            columns: [
                {
                    name: 'id',
                    type: 'int',
                    isPrimary: true,
                    isGenerated: true,
                    generationStrategy: 'increment'
                },
                {
                    name: 'email',
                    type: 'varchar',
                    isUnique: true
                }
            ]
        }));
    }

    async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.dropTable('users');
    }
}

バージョン情報

  • Version: 1.0.0