DB Migration Generator
Prerequisites & Dependencies
- Node.js 18+ with
prismaortypeorm, or Python 3.10+ withalembic, matching the project ORM - Existing ORM setup:
schema.prisma, TypeORMDataSourceconfig, oralembic.iniplusenv.py DATABASE_URLpointing to a dev database that mirrors the current production schema
Execution Steps
- Sync the dev database to the last applied migration so the diff is computed against the true current state.
- Apply model changes (edit
schema.prisma, TypeORM entities, or SQLAlchemy models). - Auto-generate a descriptively named migration using the ORM diff engine (e.g.,
add_user_email_index). - Read the generated SQL before applying: flag destructive operations (column drops, type changes, table locks on large tables) for manual review.
- Apply the migration to the dev database and verify the resulting schema (
prisma db pull,alembic current, or information_schema inspection). - Test the rollback path (
alembic downgrade -1, TypeORMmigration:revert) and document any irreversible steps for ops sign-off.
# Prisma
npx prisma migrate dev --name add_user_email_index
npx prisma migrate status
# TypeORM
npx typeorm migration:generate -d src/data-source.ts src/migrations/AddUserEmailIndex
npx typeorm migration:run -d src/data-source.ts
# Alembic
alembic revision --autogenerate -m "add user email index"
alembic upgrade head
alembic downgrade -1