Към всички skills

migration-generator

aiskillstore · Бази данни

Create database migrations from model changes, schema diffs, and migration best practices.

Оригинален текст · няма потвърден превод на български

Първо прочетете инструкцията.

Файлът се зарежда от посочения източник само по ваше действие. Можете да го прочетете тук, да го копирате или да го запазите като .md.

Оригинален SKILL.md
GitHub хранилище
Звезди на репото
428
Лиценз
Не е посочен. Проверете в репозитория.
Последна проверка на записа
Няма посочена дата

Добавете в своя инструмент.

Командата отваря избора на skills от репозитория. Прочетете файла и условията на автора преди изпълнение.

npx skills add aiskillstore/marketplace

Страницата копира текст. Не инсталира и не изпълнява нищо на устройството ви.

Откъс от SKILL.md

Началото на файла на автора, без превод.

Migration Generator Skill

Create database migrations from model changes, schema diffs, and migration best practices.

Instructions

You are a database migration expert. When invoked:

  1. Detect Schema Changes:

    • Compare current schema with desired state
    • Identify added/removed tables and columns
    • Detect modified column types and constraints
    • Find changed indexes and foreign keys
  2. Generate Migration Files:

    • Create forward (up) and backward (down) migrations
    • Use ORM-specific migration format when applicable
    • Include data migrations when needed
    • Handle edge cases and potential data loss
  3. Ensure Safety:

    • Prevent accidental data deletion
    • Add rollback capability
    • Include validation steps
    • Warn about breaking changes
  4. Best Practices:

    • Make migrations atomic and reversible
    • Avoid destructive operations in production
    • Test migrations on staging first
    • Keep migrations small and focused

Supported Frameworks

  • SQL: Raw SQL migrations (PostgreSQL, MySQL, SQLite)
  • Node.js: Prisma, TypeORM, Sequelize, Knex.js
  • Python: Alembic, Django migrations, SQLAlchemy
  • Ruby: Rails Active Record Migrations
  • Go: golang-migrate, goose
  • PHP: Laravel migrations, Doctrine

Usage Examples

@migration-generator Add user email verification
@migration-generator --from-diff
@migration-generator --rollback
@migration-generator --data-migration
@migration-generator --zero-downtime

Raw SQL Migrations

PostgreSQL - Add Table

-- migrations/001_create_users_table.up.sql
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  username VARCHAR(50) UNIQUE NOT NULL,
  email VARCHAR(255) UNIQUE NOT NULL,
  password_hash VARCHAR(255) NOT NULL,
  active BOOLEAN DEFAULT true NOT NULL,
  created_at TIMESTAMP DEFAULT NOW() NOT NULL,
  updated_at TIMESTAMP DEFAULT NOW() NOT NULL
);

-- Create indexes
CREATE INDEX idx_users_email ON users(email);
CREATE INDEX idx_users_username ON users(username);
CREATE INDEX idx_users_active ON users(active) WHERE active = true;

-- Add comments
COMMENT ON TABLE users IS 'Application users';
COMMENT ON COLUMN users.email IS 'User email address (unique)';

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

Add Column with Default Value

Целият SKILL.md в GitHub