Skip to main content

Generate migrations between Postgres databases

Project description

image image image

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.

This project is currently in active development, see Roadmap.

Table of Contents

  1. Getting Started
  2. Configuration
  3. Contributing
  4. License

Getting Started

Installation

pgmig is available as pgmig on PyPI.

Invoke pgmig directly with uvx:

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

Or install pgmig with uv (recommended) or pip:

# With uv.
uv tool install pgmig@latest  # Install pgmig globally.
uv add --dev pgmig            # Or add pgmig to your project.

# With pip.
pip install pgmig

Usage

pgmig can be used directly in the command line or as a Python library.

Command line

Print the migration SQL that makes source match target:

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

When the two structures already match, nothing is printed.

Library

The same diff is available as a function that returns the SQL as a string:

import pgmig

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

print(sql)  # the migration SQL

generate returns an empty string when the structures already match.

Configuration

pgmig has no configuration file — everything is passed on the command line (or as arguments to pgmig.generate).

pgmig generate accepts:

Option Description
--source, -s DSN of the source (current) database. Required.
--target, -t DSN of the target (desired) database. Required.
--output, -o Write the migration SQL to this file instead of stdout.

Other commands:

Command Description
pgmig --version Print the installed version.
pgmig --help Show help for any command.

A DSN is any libpq connection string, e.g. postgresql://user:pass@host:5432/dbname.

Contributing

Contributions are welcome!

See CONTRIBUTING.md for details.

License

pgmig is distributed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgmig-0.0.4.tar.gz (609.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pgmig-0.0.4-py3-none-any.whl (38.1 kB view details)

Uploaded Python 3

File details

Details for the file pgmig-0.0.4.tar.gz.

File metadata

  • Download URL: pgmig-0.0.4.tar.gz
  • Upload date:
  • Size: 609.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

File hashes

Hashes for pgmig-0.0.4.tar.gz
Algorithm Hash digest
SHA256 1db32ce73eb20f03653007d6b214a6276a65f0f7473c2e476e10809baad33b4d
MD5 909543058d489fda93835fd99bfee5e3
BLAKE2b-256 650d9f35da2df7db7b96a151c998226a868cf0d78897b61f7f80397e5ef96ae8

See more details on using hashes here.

File details

Details for the file pgmig-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pgmig-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 38.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}

File hashes

Hashes for pgmig-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4108cec6b7edffff93cb35df04e1f341e5338e884030ba5c03eb21ca87e96f97
MD5 bfd1137fa07e22fcc3504598eb879b1e
BLAKE2b-256 99d64994bb38070197e5a38e4bd84886a814cfb099ca727f196dfac788e0736c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page