home / skills / ntaksh42 / agents / database-migration-generator
This skill generates database migration scripts with up and down migrations, covering table creation, alterations, indexes, and foreign keys across databases.
npx playbooks add skill ntaksh42/agents --skill database-migration-generatorReview the files below or copy the command above to add this skill to your agents.
---
name: database-migration-generator
description: Generate 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
## 生成例
```sql
-- 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)
```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
This skill generates database migration scripts with built-in rollback support for a range of relational databases and common ORMs. It produces up/down SQL files and can scaffold migration classes for TypeORM-style projects. The output focuses on schema changes: create/drop tables, add/remove columns, indexes, and foreign keys, with clear rollback steps.
Provide the desired schema change or current/target models and the skill outputs paired migration artifacts: an "up" migration to apply changes and a "down" migration to revert them. It can emit raw SQL compatible with common dialects and scaffold migration code for TypeORM (TypeScript). Each migration includes explicit operations for schema, indexes, constraints, and timestamps to ensure safe rollbacks.
Which databases and dialects are supported?
The skill targets common relational dialects (PostgreSQL, MySQL, SQLite) and produces standard SQL and ORM scaffolding; dialect-specific adjustments may be needed for proprietary features.
Does the skill handle data migrations (transformations) as well as schema?
It primarily focuses on schema operations and reversible structural changes. Simple data transformations can be included, but complex ETL-like operations should be reviewed and tested carefully.