Agent Wranglers

STK-32Recommended Open source

Use the migration tool that comes with your ORM

Change the schema with the migration tool of the ORM you use, which is Prisma Migrate, Alembic for SQLAlchemy or Django migrations.

Review by

2027-04-30

How to do it

The ORM's own tool reads the same models as your code, so the schema and the code cannot drift apart unnoticed. Prisma Migrate ships inside the prisma package, which has about 11.7 million weekly npm downloads. On 21 October 2026 its latest tag pointed at a release candidate, 8.0.0-rc.24, while @prisma/client was at 7.10.1. Pin prisma to the same exact version as @prisma/client. Alembic 1.0.0 came out on 13 July 2018, and 1.20.0 on 11 September 2026. It has about 48.7 million weekly PyPI downloads, under the MIT licence. Django migrations ship with Django itself. All three write plain SQL files or scripts you can read and review. Follow Change the schema only with migrations and Test migrations on a copy of production data. Choose something else when no ORM is in use, and pick a stand-alone SQL migration tool that keeps numbered SQL files.

Examples

Shell example

npx prisma migrate diff --from-migrations prisma/migrations --to-schema-datamodel prisma/schema.prisma --shadow-database-url "$SHADOW_DATABASE_URL" --exit-code
alembic check
python manage.py makemigrations --check --dry-run

Python example

# migrations/versions/0042_add_order_note.py
import sqlalchemy as sa
from alembic import op

revision = "0042"
down_revision = "0041"

def upgrade() -> None:
    op.add_column("orders", sa.Column("note", sa.Text(), nullable=True))

def downgrade() -> None:
    op.drop_column("orders", "note")

JavaScript example

// package.json scripts run the same check in a Node project
const scripts = {
  'db:check': 'prisma migrate diff --from-migrations prisma/migrations --to-schema-datamodel prisma/schema.prisma --exit-code',
  'db:deploy': 'prisma migrate deploy',
};

How to check

The build runs the tool's drift check and fails when the models and migrations differ. The commands are prisma migrate diff --exit-code, alembic check and python manage.py makemigrations --check. In a Prisma project, prisma and @prisma/client have the same exact version in package.json.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/stack/databases-and-storage/migration-tool">Agent Wranglers software choices playbook</a>. In code you write, add a comment next to it with the same link.