PGPM Workspaces
Create and manage pgpm workspaces for modular PostgreSQL development. Workspaces bring npm-style modularity to database development.
When to Apply
Use this skill when:
- Starting a new modular database project
- Creating a pgpm workspace structure
- Initializing database modules
- Setting up a pnpm monorepo for database packages
Quick Start
Create a Workspace
pgpm init workspaceEnter workspace name when prompted:
? Enter workspace name: my-database-projectThis creates a complete pnpm monorepo:
my-database-project/
├── docker-compose.yml
├── pgpm.json
├── lerna.json
├── LICENSE
├── Makefile
├── package.json
├── packages/
├── pnpm-workspace.yaml
├── README.md
└── tsconfig.jsonInstall Dependencies
cd my-database-project
pnpm installCreate a Module
Inside the workspace:
pgpm initEnter module details:
? Enter module name: pets
? Select extensions: uuid-ossp, plpgsqlThis creates:
packages/pets/
├── pets.control
├── pgpm.plan
├── deploy/
├── revert/
└── verify/Workspace vs Module
Workspace: Top-level directory containing your entire project. Has pgpm.json and packages/ directory. Like an npm project root.
Module: Self-contained database package inside the workspace. Has its own pgpm.plan, .control file, and migration directories. Like an individual npm package.
Key Files
pgpm.json (Workspace Config)
{
"packages": ["packages/*"]
}Points pgpm to your modules directory.
module.control (Module Metadata)
# pets.control
comment = 'Pet adoption module'
default_version = '0.0.1'
requires = 'uuid-ossp,plpgsql'Declares module name, description, version, and dependencies.
pgpm.plan (Migration Plan)
%syntax-version=1.0.0
%project=pets
%uri=pets
schemas/pets 2025-11-14T00:00:00Z Author <author@example.com>
schemas/pets/tables/pets [schemas/pets] 2025-11-14T00:00:00Z Author <author@example.com>Tracks all changes in deployment order.
Common Commands
| Command | Description |
|---|---|
pgpm init workspace | Create new workspace |
pgpm init | Create new module in workspace |
pgpm add <change> | Add a database change |
pgpm deploy | Deploy module to database |
pgpm verify | Verify deployment |
pgpm revert | Rollback changes |
Environment Setup
Before deploying, ensure PostgreSQL is running and connection variables are loaded.
Seepgpm-dockerskill for starting PostgreSQL andpgpm-envskill for loading environment variables.
# Verify connection
psql -c "SELECT version();"
# Bootstrap database users (run once)
pgpm admin-users bootstrap --yesDeploy a Module
cd packages/pets
pgpm deploy --database pets_dev --createdb --yespgpm:
- Creates the database if needed
- Resolves dependencies
- Deploys changes in order
- Tracks deployment in
pgpm_migrateschema
Module Structure Best Practices
Organize changes hierarchically:
deploy/
└── schemas/
└── app/
├── schema.sql
├── tables/
│ └── users.sql
├── functions/
│ └── create_user.sql
└── triggers/
└── updated_at.sqlUse nested paths:
pgpm add schemas/app/schema
pgpm add schemas/app/tables/users --requires schemas/app/schema
pgpm add schemas/app/functions/create_user --requires schemas/app/tables/usersTroubleshooting
| Issue | Solution |
|---|---|
| "Cannot connect to Docker" | Start Docker Desktop first |
| "PGHOST not set" | Load PG env vars (see pgpm-env skill) |
| "Connection refused" | Ensure PostgreSQL is running (see pgpm-docker skill) |
| Module not found | Ensure you're inside a workspace with pgpm.json |
References
- Related skill:
pgpm-dockerfor Docker management - Related skill:
pgpm-envfor environment configuration - Related skill:
pgpm-changesfor authoring database changes