Skip to main content

migra: Like diff but for Postgres schemas

  • compare schemas

  • autogenerate migration scripts

  • autosync your development database from your application models

  • make your schema changes testable, robust, and (mostly) automatic

migra is a schema diff tool for PostgreSQL, written in Python. Use it in your python scripts, or from the command line like this:

$ migra postgresql:///a postgresql:///b
alter table "public"."products" add column newcolumn text;

alter table "public"."products" add constraint "x" CHECK ((price > (0)::numeric));

migra magically figures out all the statements required to get from A to B.

Most features of PostgreSQL are supported.

Usage

usage: migra [-h] [--unsafe] [--schema SCHEMA] [--exclude_schema EXCLUDE_SCHEMA] [--create-extensions-only] [--ignore-extension-versions] [--with-privileges] [--force-utf8] dburl_from dburl_target

Installing

Cogna publishes this fork to PyPI as cogna-migra. It installs the same top-level migra package as migra and migra-maintained, so installing it alongside either one overwrites files, and uninstalling one breaks the other. Uninstall them first:

pip uninstall migra migra-maintained schema-inspect-maintained
pip install cogna-migra

It depends on cogna-schemainspect in place of schemainspect or schema-inspect-maintained.

Command Line

pip install cogna-migra
migra db_url_from db_url_target

Python

pip install cogna-migra
# The import name is still migra
from migra import Migration, Statements
from migra.command import parse_args, run

Docker

No image is published for this fork. Build one locally from the Dockerfile, which installs cogna-migra from PyPI:

./build-docker.sh
docker run --rm migra:latest \
  postgresql://user:password@host1:port/dbname1 \
  postgresql://user:password@host2:port/dbname2

Migra supports PostgreSQL >= 9 only. Known issues exist with earlier versions. More recent versions are more comprehensively tested. Development resources are limited, and feature support rather than backwards compatibility is prioritised.

Contributing

Contributing is easy. Jump into the issues, find a feature or fix you'd like to work on, and get involved. Or create a new issue and suggest something completely different. If you're unsure about any aspect of the process, just ask.

See the Contribution Guide for more details

Roadmap

The dream would be to develop this to a point where we no longer need to manually write migrations, just use version control to manage the schema of a database.

Features

View ownership

RLS policies

Other entities

Robustness

  • Proper pg10 - pg17 support
    • (Currently runs test on 16/17 for philipwee/migra and 10-15 for philipwee/schemainspect because of breaking internal postgres changes in pg_get_viewdef from 15-16 (and possibly pg_get_functiondef and pg_get_expr))
  • Proper documentation website

The current aim is to fix all of the main caveats listed in the supabase docs

Contributions are extremely welcome, and there should be enough info in the Contribution Guide to get you started!

Reason for forking

This repo was forked because the original migra package had several limitations but has been unmainted for about 4 years.

While there are alternatives such as stripe's pg-schema-diff, somehow this package still remains as one of the robust ways of diffing two db schemas because it handles dependencies between objects pretty well

Folks, schemas are good

Schema migrations are without doubt the most cumbersome and annoying part of working with SQL databases. So much so that some people think that schemas themselves are bad!

But schemas are actually good. Enforcing data consistency and structure is a good thing. It’s the migration tooling that is bad, because it’s harder to use than it should be. migra is an attempt to change that, and make migrations easy, safe, and reliable instead of something to dread.

Credits

A huge shoutout to djrobstep for the initial development, maintenance of the migra package

Metadata

Release files for cogna-migra 1.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cogna-migra 1.1.3
File Size Uploaded Provenance Actions
cogna_migra-1.1.3.tar.gz 12.7 kB With provenance Details for cogna_migra-1.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cogna-migra 1.1.3
File Interpreter ABI Platform Actions
cogna_migra-1.1.3-py3-none-any.whl Python 3 none any Details for cogna_migra-1.1.3-py3-none-any.whl

Total release size: 25.2 kB

Release files / cogna_migra-1.1.3.tar.gz

Download URL cogna_migra-1.1.3.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c54d64a350f3741243402cfd1141f5609273f6fe243e9661d2750bed30776456
BLAKE2b-256 checksum
How to use checksums
89f732ca542531c598b75e81c3da5e48219a599c4885804d1fef1f2083eeb6b8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Release files / cogna_migra-1.1.3-py3-none-any.whl

Download URL cogna_migra-1.1.3-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b06290ad19eabb102b9915e55cb53cf00cb9ee22c51b6ea34c6902ab8d050bb
BLAKE2b-256 checksum
How to use checksums
805f6b570f5a838e1e5eece00a8c124c13dca5fd4118f54dc5924b6bec738c89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

Security for cogna-migra 1.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cogna_migra-1.1.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.3 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page