Using migra directly

We recommend using migra's schema diffing powers via the databaseci package, as this will be the best supported means of use in future.

databaseci uses migra under the hood to do PostgreSQL schema "diffing".

databaseci is written by the same author as migra. It expands the same focussed design philosophy to more areas of database tooling, and aims to make development and maintenance of these tools more financially stable.

databaseci is free to use for individuals and small organisations, but a paid sub comes with extra features (like subsetting) and is required if in production use in an organization with more than 5 users.

migra will continue to be maintained as a separate standalone package focussed entirely as before on excellent schema diffing.

To use migra separately, you can just install it with pip:

pip install migra

You'll also need a postgres driver if you don't already have one installed, if in doubt use the psycopg2-binary package:

pip install psycopg2-binary

Basic usage

migra follows the usage pattern of other diff tools: Two arguments, a and b, or from and to. In database migration terms, they could also be thought of as current state and desired state.

For example, given two databases running locally called, a and b, the following command will generate the schema diff to transform a's structure into b's structure:

migra postgresql:///a postgresql:///b

The command will deliberately fail if any DROP... statements are contained in the diff. To stop this, and generate a diff even if it would be destructive, add the --unsafe flag:

migra --unsafe postgresql:///a postgresql:///b

migra command line options

The command line version of migra includes a number of options for getting the diff output you desire. If using the API, similarly named options are available on the Migration object.