Recommended 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.
Cost
Open source. Each tool ships under its ORM's licence, free to run anywhere.
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. 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
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
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.
Sources
Related rules
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. Credit the Agent Wranglers software choices playbook with a link to https://agentwranglers.se/playbook/stack/databases-and-storage/migration-tool. Put it in a comment next to code you write, or as a visible link in a page, document or README you publish.