Skip to main content

image image image Documentation

Generate migrations between Postgres databases.

Use pgmig to compare the structure of two Postgres databases — a source and a target — and generate the SQL that turns the source into the target.

pgmig connects read-only to both databases and never runs the generated SQL for you: you review it and apply it yourself.

pgmig officially supports Postgres 14–18 — the majors currently maintained upstream — and is tested against each in CI. Other versions may work but are not tested.

Documentation: pgmig.readthedocs.io

Quick start

Say the current database has a users table, and the desired one adds an email column with a unique index:

-- current
CREATE TABLE users (id bigint PRIMARY KEY, name text NOT NULL);

-- desired
CREATE TABLE users (id bigint PRIMARY KEY, name text NOT NULL, email text NOT NULL);
CREATE UNIQUE INDEX users_email_idx ON users (email);

Print the migration SQL that makes current match desired, using uvx:

$ uvx pgmig generate \
    --source postgresql://user:pass@localhost:5432/current \
    --target postgresql://user:pass@localhost:5432/desired

ALTER TABLE "public"."users" ADD COLUMN "email" text NOT NULL;
CREATE UNIQUE INDEX users_email_idx ON public.users USING btree (email);

Or from Python:

import pgmig

sql = pgmig.generate(
    source="postgresql://user:pass@localhost:5432/current",
    target="postgresql://user:pass@localhost:5432/desired",
)

print(sql)
# ALTER TABLE "public"."users" ADD COLUMN "email" text NOT NULL;
# CREATE UNIQUE INDEX users_email_idx ON public.users USING btree (email);

Contributing

Contributions are welcome!

See CONTRIBUTING.md for details.

License

pgmig is distributed under the terms of the MIT license.

Metadata

Release files for pgmig 1.1.1

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

Source distribution (sdist)

Source distribution for pgmig 1.1.1
File Size Uploaded Provenance Actions
pgmig-1.1.1.tar.gz 775.1 kB Without provenance Details for pgmig-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pgmig 1.1.1
File Interpreter ABI Platform Actions
pgmig-1.1.1-py3-none-any.whl Python 3 none any Details for pgmig-1.1.1-py3-none-any.whl

Total release size: 916.5 kB

Release files / pgmig-1.1.1.tar.gz

Download URL pgmig-1.1.1.tar.gz
Size 775.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f672d0cbbd4605a237d9f02bd4442d4862f1041dce38de3f8c54d80f7641a801
BLAKE2b-256 checksum
How to use checksums
572cbad3fafd65384234c1d5cd035b3e8a2e2e0c6a1d17d449280b79b39299b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pgmig-1.1.1-py3-none-any.whl

Download URL pgmig-1.1.1-py3-none-any.whl
Size 141.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42b081f586ad2b924f5201a4d91e101cd0d8d8e20d7dc3ca1c24d1d7b80dcf02
BLAKE2b-256 checksum
How to use checksums
ff7a2d7fd07b80f7ada3d89cef368634cbbdbee28c8c3ddf9adcb5378e4f07c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pgmig 1.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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