skillfed

migra

Like `diff` but for PostgreSQL schemas

migra v3.0.1663481299 246.9K downloads/30d#8,703 on PyPI3,051
Permissive license Unlicense AGING released

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 migra

uv

uv add migra

poetry

poetry add migra

Installing 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

License :: Other/Proprietary LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

postgres schema diffdatabase migration generatorpostgresql schema comparisonauto-generate sql migrationsschema synchronization tooldatabase schema versioningpostgres schema changes
schema-migrationpostgres-toolssql-generation

More Database packages

psycopg2-binary

psycopg2-binary is a PostgreSQL database…

copyleft · top 1,000 on PyPI

redis

Python client library for connecting to and…

permissive · top 1,000 on PyPI

ydb

YDB Python SDK is the official client library…

permissive · top 1,000 on PyPI

snowflake-connector-python

Connects Python applications to Snowflake data…

permissive · top 1,000 on PyPI

sqlparse

sqlparse tokenizes SQL text into a tree of…

permissive · top 1,000 on PyPI

dbt-adapters

Provides base adapter protocols and shared…

permissive · top 1,000 on PyPI

django-pg-zero-downtime-migrations

Provides a Django database backend for…

permissive · top 15,000 on PyPI

sqlalchemy-diff

Compares database schemas across two…

permissive · top 15,000 on PyPI

alembic

Alembic generates and manages database schema…

permissive · top 1,000 on PyPI

schemachange

schemachange is a Python tool that manages…

permissive · top 15,000 on PyPI

atlas-provider-sqlalchemy

Connects SQLAlchemy models to Atlas to…

unclear · top 15,000 on PyPI

squawk-cli

Linter that analyzes PostgreSQL migrations and…

permissive · top 15,000 on PyPI

schemainspect

Inspects PostgreSQL database schemas to extract…

permissive · top 15,000 on PyPI

yoyo-migrations

Yoyo-migrations is a database schema migration…

permissive · top 15,000 on PyPI

alembic-autogenerate-enums

Extends Alembic's autogenerate to detect and…

permissive · top 15,000 on PyPI

alembic-postgresql-enum

Extends Alembic to automatically detect and…

permissive · top 5,000 on PyPI