migra
Like `diff` but for PostgreSQL schemas
What it is and what it does
migra is a schema diff tool for PostgreSQL that automatically detects differences between two database schemas and generates the SQL statements needed to transform one into the other. Instead of writing migrations by hand, you point migra at a source and target schema, and it figures out the alter statements required—column additions, constraint changes, and other modifications across most PostgreSQL features. It works both as a command-line tool and as a library you can call from Python scripts.
The tool is designed to make schema migrations less tedious and error-prone by automating the comparison and SQL generation. You can use it to synchronize a development database from application models, make schema changes testable, or simply understand what structural changes exist between two database versions. It requires PostgreSQL >= 9 and Python >= 3.7, with minimal dependencies (sqlbag, six, schemainspect).
Use it for:
- Generate migration scripts automatically when your application schema definition changes, reducing manual SQL writing.
- Synchronize a development database schema with your application's ORM or schema models without hand-coding migrations.
- Compare production and staging database schemas to identify drift and generate corrective SQL statements.
- Test schema changes in a controlled way by generating and reviewing the exact SQL before applying it.
- Audit schema differences between database versions or environments for compliance or debugging purposes.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
migra compares PostgreSQL database schemas and generates the SQL statements needed to transform one schema into another, automating schema migrations from the command line or within Python scripts.
Yes, if you work regularly with PostgreSQL schema migrations and want to reduce manual SQL writing. The low install friction and permissive license make it easy to try. However, the aging maintenance status (latest release 2022, though recent commits exist) means you should verify compatibility with your PostgreSQL version and be prepared to contribute fixes if needed. No known vulnerabilities.
Install
migra on PyPI
pip
pip install migrauv
uv add migrapoetry
poetry add migraInstalling migra
Before you install
Low install friction with only three runtime dependencies. Maintenance status is aging—the latest release was in 2022, though the repository remains active with recent commits and no archived status.
License in practice
Licensed under the Unlicense, a permissive public-domain-like license that places no restrictions on use, modification, or distribution.
Quickstart
$ pip install migra
$ migra postgresql:///source_db postgresql:///target_db
Or in Python:
from migra import Migration
from sqlbag import connect
m = Migration(connect('postgresql:///a'), connect('postgresql:///b'))
print(m.sql)
Requires PostgreSQL >= 9 and Python >= 3.7, < 4. Both source and target databases must be accessible via connection strings.
Verify before relying
- Extent of PostgreSQL feature coverage beyond the 'most features' claim in the description
- Performance characteristics when comparing large or complex schemas
- Whether the aging maintenance status affects compatibility with recent PostgreSQL versions
Package facts
| License | Unlicense (permissive) |
| Python support | supports the current Python release (>=3.7,<4) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — sqlbag, six, schemainspect |
| Maintenance | aging — 1,426 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 246,944/month — #8,703 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: migra-3.0.1663481299-py3-none-any.whl
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
django-pg-zero-downtime-migrationsProvides a Django database backend for…
permissive · top 15,000 on PyPI
sqlalchemy-diffCompares database schemas across two…
permissive · top 15,000 on PyPI
alembicAlembic generates and manages database schema…
permissive · top 1,000 on PyPI
schemachangeschemachange is a Python tool that manages…
permissive · top 15,000 on PyPI
atlas-provider-sqlalchemyConnects SQLAlchemy models to Atlas to…
unclear · top 15,000 on PyPI
squawk-cliLinter that analyzes PostgreSQL migrations and…
permissive · top 15,000 on PyPI
schemainspectInspects PostgreSQL database schemas to extract…
permissive · top 15,000 on PyPI
yoyo-migrationsYoyo-migrations is a database schema migration…
permissive · top 15,000 on PyPI
alembic-autogenerate-enumsExtends Alembic's autogenerate to detect and…
permissive · top 15,000 on PyPI
alembic-postgresql-enumExtends Alembic to automatically detect and…
permissive · top 5,000 on PyPI