---
title: "Use the migration tool that comes with · Agent Wranglers"
url: https://agentwranglers.se/playbook/stack/databases-and-storage/migration-tool
updated: 2026-10-21
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Use the migration tool that comes with your ORM

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers). Updated 2026-10-21.

For AI agents: [llms.txt](https://agentwranglers.se/llms.txt) is a short guide that sends you to the rules your problem needs, and [rules.json](https://agentwranglers.se/playbook/stack/rules.json) holds every rule of this playbook as JSON.

- Level: Recommended
- Chapter: [Databases and storage](https://agentwranglers.se/playbook/stack/databases-and-storage)
- Rule: Change the schema with the migration tool of the ORM you use, which is Prisma Migrate, Alembic for SQLAlchemy or Django migrations.
- Cost: Open source. Each tool ships under its ORM's licence, free to run anywhere.
- How: 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. 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](https://agentwranglers.se/playbook/data/migrations/versioned-migrations) and [Test migrations on a copy of production data](https://agentwranglers.se/playbook/data/migrations/test-migrations). Choose something else when no ORM is in use, and pick a stand-alone SQL migration tool that keeps numbered SQL files.
- 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`.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Shell example

```sh
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

```python
# 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

```js
// 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',
};
```

## Sources

- [Alembic](https://alembic.sqlalchemy.org/)
- [Prisma Migrate](https://www.prisma.io/docs/orm/prisma-migrate)

## Related rules

- [Change the schema only with migrations](https://agentwranglers.se/playbook/data/migrations/versioned-migrations) in Data
- [Test migrations on a copy of production data](https://agentwranglers.se/playbook/data/migrations/test-migrations) in Data

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/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.

- Previous: [Use a mature ORM for database code](https://agentwranglers.se/playbook/stack/databases-and-storage/orm)
- Next: [Use PostgreSQL search first and OpenSearch when it falls short](https://agentwranglers.se/playbook/stack/databases-and-storage/full-text-search)
- [Databases and storage](https://agentwranglers.se/playbook/stack/databases-and-storage)
