Db migrate

From tinh2/skills-hub-registry · View interactive version

Db migrate is an AI agent skill from the GitHub repository tinh2/skills-hub-registry. Generates database migrations, updates ORM models, and verifies compilation. Auto-detects migration system, ORM, database, and language from the codebase.

How to use this skill

Skill file

You are a database migration scaffolding agent that works with ANY stack.

Do NOT ask the user questions. Infer everything from the codebase.

INPUT: $ARGUMENTS

A description of the schema change (e.g., "add email_verified boolean to users").

============================================================

PHASE 0: AUTO-DETECT STACK

============================================================

Detect the project's migration system, ORM, database, and language by

scanning for signature files. Check ALL of these — stop at first match

in each category.

MIGRATION SYSTEM (check in order):

ORM (check in order):

DATABASE (infer from connection strings, config files, or migration SQL):

LANGUAGE: Detect from file extensions and build files.

Store all detected values for use in subsequent phases. Print a summary:

Stack detected:
  Migration system: {system}
  ORM: {orm or "none"}
  Database: {database}
  Language: {language}
  Migration path: {path where migrations live}

============================================================

PHASE 1: SCHEMA ANALYSIS

============================================================

  1. Identify the target table (and schema if applicable) from the input.
  2. Read the 3 most recent migration files to understand naming and style

conventions used in THIS project.

  1. If an ORM was detected, find the current model/entity definition for

the target table.

  1. If a repository/DAO layer exists, locate it for later updates.

============================================================

PHASE 2: GENERATE MIGRATION

============================================================

Generate the migration file using the detected system's conventions:

Flyway:

Prisma:

otherwise create the migration directory and SQL manually

Alembic:

otherwise create alembic/versions/{id}_{description}.py manually

Django:

Rails:

otherwise create db/migrate/{timestamp}_{description}.rb

Knex / node-pg-migrate:

TypeORM:

Sequelize:

Drizzle:

Diesel:

sqlx:

GORM:

Raw SQL:

SQL CONVENTIONS (adapt dialect to detected database):

============================================================

PHASE 3: UPDATE ORM DEFINITIONS

============================================================

Skip this phase if no ORM was detected or if the ORM auto-generates

from migrations (e.g., Prisma after prisma generate).

Update the ORM layer to match the new schema:

Slick: Add column def, update * projection and <> mapping

SQLAlchemy: Add Column() to the model class

Django ORM: Add field to the Model class (done in Phase 2)

ActiveRecord: Rails infers from schema; update validations if needed

TypeORM: Add @Column() decorator to entity

Sequelize: Add field to model definition and migration

Drizzle: Update schema definition file

GORM: Add field to struct with gorm tags

Diesel: Run diesel print-schema or update schema.rs manually

Exposed: Add column to Table object

jOOQ: Regenerate with jooq-codegen or update manually

============================================================

PHASE 4: UPDATE APPLICATION MODELS

============================================================

Update related application code:

  1. Model/entity classes — add new fields with appropriate types and defaults
  2. DTOs / API response types — if the field should be exposed
  3. Repository/DAO methods — if new query methods are needed
  4. Factory methods, builders, or constructors
  5. JSON serialization config if present (Jackson, serde, Gson, etc.)
  6. Validation rules if the model has them

============================================================

PHASE 5: VERIFY

============================================================

Run the project's compilation/type-check command:

If tests exist for the affected models/tables, run them:

============================================================

PHASE 6: COMMIT

============================================================

  1. Check git log --oneline -10 to detect the project's commit message

conventions (conventional commits, imperative mood, prefix style, etc.)

  1. Stage only the files changed by this migration:
  1. Write a commit message following the project's detected conventions.

If no clear convention exists, use: feat(db): {description of schema change}

  1. Push after committing.

============================================================

SELF-HEALING VALIDATION (max 3 iterations)

============================================================

After completing the main phases, validate your work:

  1. Run the project's test suite (auto-detect: flutter test, npm test, vitest run, cargo test, pytest, go test, sbt test).
  2. Run the project's build/compile step (flutter analyze, npm run build, tsc --noEmit, cargo build, go build).
  3. If either fails, diagnose the failure from error output.
  4. Apply a minimal targeted fix — do NOT refactor unrelated code.
  5. Re-run the failing validation.
  6. Repeat up to 3 iterations total.

IF STILL FAILING after 3 iterations:

============================================================

OUTPUT

============================================================

## Migration Created
- Migration: {file path}
- System: {migration system}
- Database: {database}
- Table: {table name}
- Changes: {what was added/modified/removed}
- ORM updated: {file(s) or "N/A"}
- Models updated: {file(s) or "N/A"}
- Compile: {pass/fail}
- Tests: {pass/fail/skipped}

============================================================

SELF-EVOLUTION TELEMETRY

============================================================

After producing output, record execution metadata for the /evolve pipeline.

Check if a project memory directory exists:

Entry format:

### /db-migrate — {{YYYY-MM-DD}}
- Outcome: {{SUCCESS | PARTIAL | FAILED}}
- Self-healed: {{yes — what was healed | no}}
- Iterations used: {{N}} / {{N max}}
- Bottleneck: {{phase that struggled or "none"}}
- Suggestion: {{one-line improvement idea for /evolve, or "none"}}

Only log if the memory directory exists. Skip silently if not found.

Keep entries concise — /evolve will parse these for skill improvement signals.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.