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: migra [-h] [--unsafe] [--schema SCHEMA] [--exclude_schema EXCLUDE_SCHEMA] [--create-extensions-only] [--ignore-extension-versions] [--with-privileges] [--force-utf8] dburl_from dburl_target
pip install migra-maintained
migra db_url_from db_url_targetpip install migra-maintained# Use migra_maintained instead of migra-maintained
from migra_maintained import Migration, Statements
from migra_maintained.command import parse_args, rundocker pull philipandrewweedewang/migra:latest
docker run --rm philipandrewweedewang/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 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
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.
- view owner and grants
- security invoker on views
- materialized views
- doesn't recreate views when altering column type
- Fix enum dependencies on functions
- Basic comments support
- Support for comments with dependencies
- schema privileges are not tracked because each schema is diffed separately
- partitions are not tracked
-
alter publication ... add table ... - create domain statements are ignored
- grant statements are duplicated from default privileges
- Proper pg10 - pg17 support
- (Currently runs test on 16/17 for
philipwee/migraand 10-15 forphilipwee/schemainspectbecause of breaking internal postgres changes inpg_get_viewdeffrom 15-16 (and possiblypg_get_functiondefandpg_get_expr))
- (Currently runs test on 16/17 for
- 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!
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
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.
A huge shoutout to djrobstep for the initial development, maintenance of the migra package