PostgreSQL Package Manager CLI

4.16.3 · active · verified Wed Apr 22

pgpm is a powerful and opinionated command-line interface (CLI) for managing PostgreSQL database schemas, migrations, and modules, akin to a package manager for your database. It is designed for modular PostgreSQL development, enabling the creation and management of reusable database packages with dependency resolution and semantic versioning. The tool features a deterministic migration engine, offering version-controlled, plan-driven deployments with rollback capabilities and idempotent execution. It supports recursive module resolution across workspaces and provides turnkey module-first workspaces ready for CI/CD, Docker, and end-to-end testing with TypeScript tooling. The current stable version is 4.16.3, and it appears to be actively maintained with a focus on robust and reproducible database development workflows.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates global installation, starting a local PostgreSQL instance via Docker, initializing a workspace and a module, adding a basic migration, and deploying changes to the database.

# Install pgpm globally
npm install -g pgpm

# Start a local PostgreSQL instance using Docker and export environment variables
pgpm docker start
eval "$(pgpm env)"

# Create a new pgpm workspace
pgpm init workspace my-app
cd my-app

# Create your first database module within the workspace
pgpm init packages/my-module
cd packages/my-module

# Add a sample migration (e.g., create a users table)
# Create src/migrations/001_create_users_table.sql with content:
/*
create table users (
  id serial primary key,
  name text not null
);
*/

# Return to the workspace root
cd ../..

# Deploy all changes and modules to the database, creating the database if it doesn't exist
pgpm deploy --createdb --database mydatabase

console.log("pgpm workspace and initial module deployed successfully!")

view raw JSON →