This skill generates database migration scripts.
Main Features
- Table Creation: CREATE TABLE
- Add/Remove Columns: ALTER TABLE
- Index: CREATE INDEX
- Foreign Keys: FOREIGN KEY constraints
- Rollback: DOWN migration
Generation Example
-- 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 Information
- Version: 1.0.0