pgpkg¶
A small, focused PostgreSQL migration toolkit.
pgpkg replaces the stageversion, makemigration, and migrate flow
made popular by pypgstac, but in a reusable form with zero project-specific
code. You own:
- an ordered
sql/directory that describes the exact state the database should be in, and sql/pre/andsql/post/directories whose contents run around every migration (roles, grants, settings).
pgpkg does everything else:
- stageversion — renders
sql/into<prefix>--<version>.sql - makemigration — diffs two staged versions into
<prefix>--<from>--<to>.sqlusingresults.temporary_local_db+results.schemadiff_as_sql - graph / plan — show the version graph and the shortest path to a target version
- migrate — apply the plan inside one transaction with an advisory lock,
tracking applied versions in
pgpkg.migrations - verify — round-trip every edge
a -> bthrough two temp DBs and confirmbase(a) + a→b = base(b) - wheel — scaffold a tiny wrapper Python project that bakes the staged artifacts into a wheel + console script
- bundle — emit a raw
tar.zstartifact with migrations plus pre/post SQL
Install¶
uv tool install pgpkg # core
uv tool install --with 'pgpkg[diff]' pgpkg # + results for makemigration/verify