pgpm β a Postgres Package Manager
A modern CLI for modular PostgreSQL development.
pgpm is a focused command-line tool for PostgreSQL database migrations and package management. It provides the core functionality for managing database schemas, migrations, and module dependencies.
β¨ Features
- π¦ Postgres Module System β Reusable, composable database packages with dependency management, per-module plans, and versioned releases
- π Deterministic Migration Engine β Version-controlled, plan-driven deployments with rollback support and idempotent execution enforced by dependency and validation safeguards.
- π Recursive Module Resolution β Recursively resolves database package dependencies (just like npm) from plan files or SQL headers, producing a reproducible cross-module migration graph.
- π·οΈ Tag-Aware Versioning - Deploy to @tags, resolve tags to changes, and reference tags across modules for coordinated releases
- π Portable Postgres Development β Rely on standard SQL migrations for a workflow that runs anywhere Postgres does.
- π Turnkey Module-First Workspaces β
pgpm init delivers a ready-to-code Postgres workspace with CI/CD, Docker, end-to-end testing, and modern TS tooling.
π Quick Start
Install & Setup
npm install -g pgpm
pgpm docker start
eval "$(pgpm env)"
Tip: Already running Postgres? Skip the Docker step and just export your PG* vars.
Create a Workspace and Install a Package
pgpm init workspace
cd my-app
pgpm init
cd packages/your-module
pgpm install @pgpm/faker
pgpm deploy --createdb --database mydb1
psql -d mydb1 -c "SELECT faker.city('MI');"
> Ann Arbor
π οΈ Commands
Here are some useful commands for reference:
Getting Started
pgpm init - Initialize a new module
pgpm init workspace - Initialize a new workspace
pgpm init --template <path> - Initialize using a full template path (e.g., pnpm/module)
pgpm init -w - Create a workspace first, then create the module inside it
Development Setup
pgpm docker start - Start PostgreSQL container (via Docker)
pgpm docker stop - Stop PostgreSQL container
pgpm env - Print PostgreSQL environment variables for shell export
Database Operations
pgpm deploy - Deploy database changes and migrations
pgpm verify - Verify database state matches expected migrations
pgpm revert - Safely revert database changes
Migration Management
pgpm migrate - Comprehensive migration management
pgpm migrate init - Initialize migration tracking
pgpm migrate status - Check migration status
pgpm migrate list - List all changes
pgpm migrate deps - Show change dependencies
Module Management
pgpm install - Install database modules as dependencies
pgpm upgrade-modules - Upgrade installed modules to latest versions
pgpm extension - Interactively manage module dependencies
pgpm tag - Version your changes with tags
Packaging and Distribution
pgpm plan - Generate deployment plans for your modules
pgpm package - Package your module for distribution
Testing
pgpm test-packages - Run integration tests on all modules in a workspace
Utilities
pgpm add - Add a new database change
pgpm remove - Remove a database change
pgpm export - Export migrations from existing databases
pgpm clear - Clear database state
pgpm kill - Clean up database connections
pgpm analyze - Analyze database structure
pgpm rename - Rename database changes
pgpm admin-users - Manage admin users
pgpm cache clean - Clear cached template repos used by pgpm init
pgpm update - Install the latest pgpm version from npm
π‘ Common Workflows
Starting a New Project and Adding a Change
pgpm init workspace
cd my-app
pgpm init
cd packages/new-module
pgpm add some_change
pgpm deploy --createdb
π§° Templates, Caching, and Updates
pgpm init now scaffolds workspaces/modules from https://github.com/constructive-io/pgpm-boilerplates.git using create-gen-app with a one-week cache (stored under ~/.pgpm/cache/repos). Override with --repo, --from-branch, and --template, or use a local template path.
- Run
pgpm cache clean to wipe the cached boilerplates if you need a fresh pull.
- The CLI performs a lightweight npm version check at most once per week (skipped in CI or when
PGPM_SKIP_UPDATE_CHECK is set). Use pgpm update to upgrade to the latest release.
Working with Existing Projects
cd packages/your-module
pgpm install @pgpm/faker
pgpm deploy --createdb --database mydb1
psql -d mydb1 -c "SELECT faker.city('MI');"
> Ann Arbor
Testing a pgpm module in a workspace
pnpm install
cd packages/yourmodule
pnpm test:watch
Database Operations
pgpm deploy
Deploy your database changes and migrations.
pgpm deploy
pgpm deploy --createdb
pgpm deploy --package mypackage --to @v1.0.0
pgpm deploy --fast --no-tx
pgpm verify
Verify your database state matches expected migrations.
pgpm verify
pgpm verify --package mypackage
pgpm revert
Safely revert database changes.
pgpm revert
pgpm revert --to @v1.0.0
Migration Management
pgpm migrate
Comprehensive migration management.
pgpm migrate init
pgpm migrate status
pgpm migrate list
pgpm migrate deps
Module Management
pgpm install
Install pgpm modules as dependencies.
pgpm install @pgpm/base32
pgpm install @pgpm/base32 @pgpm/faker
pgpm upgrade-modules
Upgrade installed pgpm modules to their latest versions from npm.
pgpm upgrade-modules
pgpm upgrade-modules --all
pgpm upgrade-modules --dry-run
pgpm upgrade-modules --modules @pgpm/base32,@pgpm/faker
pgpm upgrade-modules --workspace --all
Options:
--all - Upgrade all modules without prompting
--dry-run - Show what would be upgraded without making changes
--modules <names> - Comma-separated list of specific modules to upgrade
--workspace - Upgrade modules across all packages in the workspace
--cwd <directory> - Working directory (default: current directory)
pgpm extension
Interactively manage module dependencies.
pgpm extension
pgpm tag
Version your changes with tags.
pgpm tag v1.0.0
pgpm tag v1.0.0 --comment "Initial release"
pgpm tag v1.1.0 --package mypackage --changeName my-change
Packaging and Distribution
pgpm plan
Generate deployment plans for your modules.
pgpm plan
pgpm package
Package your module for distribution.
pgpm package
pgpm package --no-plan
Utilities
pgpm dump
Dump a postgres database to a sql file.
pgpm dump --database mydb
pgpm dump
pgpm dump --database mydb --out ./backup.sql
pgpm dump --database mydb --cwd ./packages/my-module
pgpm dump --database mydb --database-id <uuid>
pgpm export
Export migrations from existing databases.
pgpm export
pgpm kill
Clean up database connections and optionally drop databases.
pgpm kill
pgpm kill --no-drop
Testing
pgpm test-packages
Run integration tests on all modules in a workspace. Creates a temporary database for each module, deploys, and optionally runs verify/revert/deploy cycles.
pgpm test-packages
pgpm test-packages --full-cycle
pgpm test-packages --continue-on-fail
pgpm test-packages --exclude my-module,another-module
pgpm test-packages --full-cycle --continue-on-fail --exclude legacy-module
Options:
--full-cycle - Run full deploy/verify/revert/deploy cycle (default: deploy only)
--continue-on-fail - Continue testing all packages even after failures (default: stop on first failure)
--exclude <modules> - Comma-separated module names to exclude
--cwd <directory> - Working directory (default: current directory)
Notes:
- Discovers modules from workspace
pgpm.json configuration
- Creates isolated test databases (
test_<module_name>) for each module
- Automatically cleans up test databases after each test
- Uses internal APIs for deploy/verify/revert operations
βοΈ Configuration
Environment Variables
pgpm uses standard PostgreSQL environment variables (PGHOST, PGPORT, PGDATABASE, PGUSER, PGPASSWORD).
Quick setup (recommended):
eval "$(pgpm env)"
Manual setup (if you prefer):
export PGHOST=localhost
export PGPORT=5432
export PGDATABASE=myapp
export PGUSER=postgres
export PGPASSWORD=password
Supabase local development:
eval "$(pgpm env --supabase)"
Getting Help
Command Help
pgpm --help
pgpm deploy --help
pgpm tag -h
Common Options
Most commands support these global options:
--help, -h - Show help information
--version, -v - Show version information
--cwd <dir> - Set working directory
AI Agent Skills
Install the pgpm skill for AI coding agents (Devin, Claude Code, Cursor, Copilot):
npx skills add https://github.com/constructive-io/constructive --skill pgpm
For the full Constructive platform skills (security, blueprints, codegen, billing, etc.):
npx skills add constructive-io/constructive-skills
Education and Tutorials
-
π Quickstart: Getting Up and Running
Get started with modular databases in minutes. Install prerequisites and deploy your first module.
-
π¦ Modular PostgreSQL Development with Database Packages
Learn to organize PostgreSQL projects with pgpm workspaces and reusable database modules.
-
βοΈ Authoring Database Changes
Master the workflow for adding, organizing, and managing database changes with pgpm.
-
π§ͺ End-to-End PostgreSQL Testing with TypeScript
Master end-to-end PostgreSQL testing with ephemeral databases, RLS testing, and CI/CD automation.
-
β‘ Supabase Testing
Use TypeScript-first tools to test Supabase projects with realistic RLS, policies, and auth contexts.
-
π§ Drizzle ORM Testing
Run full-stack tests with Drizzle ORM, including database setup, teardown, and RLS enforcement.
-
π§ Troubleshooting
Common issues and solutions for pgpm, PostgreSQL, and testing.
Related Constructive Tooling
π¦ Package Management
- pgpm: π₯οΈ PostgreSQL Package Manager for modular Postgres development. Works with database workspaces, scaffolding, migrations, seeding, and installing database packages.
π§ͺ Testing
- pgsql-test: π Isolated testing environments with per-test transaction rollbacksβideal for integration tests, complex migrations, and RLS simulation.
- pgsql-seed: π± PostgreSQL seeding utilities for CSV, JSON, SQL data loading, and pgpm deployment.
- supabase-test: π§ͺ Supabase-native test harness preconfigured for the local Supabase stackβper-test rollbacks, JWT/role context helpers, and CI/GitHub Actions ready.
- graphile-test: π Authentication mocking for Graphile-focused test helpers and emulating row-level security contexts.
- pg-query-context: π Session context injection to add session-local context (e.g.,
SET LOCAL) into queriesβideal for setting role, jwt.claims, and other session settings.
π§ Parsing & AST
- pgsql-parser: π SQL conversion engine that interprets and converts PostgreSQL syntax.
- libpg-query-node: π Node.js bindings for
libpg_query, converting SQL into parse trees.
- pg-proto-parser: π¦ Protobuf parser for parsing PostgreSQL Protocol Buffers definitions to generate TypeScript interfaces, utility functions, and JSON mappings for enums.
- @pgsql/enums: π·οΈ TypeScript enums for PostgreSQL AST for safe and ergonomic parsing logic.
- @pgsql/types: π Type definitions for PostgreSQL AST nodes in TypeScript.
- @pgsql/utils: π οΈ AST utilities for constructing and transforming PostgreSQL syntax trees.
π Documentation & Skills
- constructive-skills: π Platform documentation and AI agent skills β feature catalog, blueprint reference, SDK guides (i18n, billing, limits, events, uploads, security, entities, search, AI), and deployment guides.
Install skills for AI coding agents:
npx skills add constructive-io/constructive-skills
npx skills add https://github.com/constructive-io/constructive --skill pgpm
npx skills add https://github.com/constructive-io/constructive --skill constructive-testing
Credits
π Built by the Constructive team β creators of modular Postgres tooling for secure, composable backends. If you like our work, contribute on GitHub.
Disclaimer
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED "AS IS", AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.