pgmi Documentation#
pgmi loads your project files into one PostgreSQL session and runs the deploy.sql you write. Three ideas carry it:
- Your SQL runs the deploy: transactions, execution order and logic.
- A test tree can gate the commit:
CALL pgmi_test()tests the changed database beforeCOMMIT. - Coding agents get tools and project skills:
pgmi serve,pgmi ai contract, and theAGENTS.mdand skills the basic and advanced templates write.
The templates are optional starting points that become your project’s code; a hand-written deploy.sql works without one.
Recommended Reading Order#
New to pgmi? Start here:
- Quickstart — Deploy your first project
- Choose a template — Minimal, basic and advanced side by side
- Why pgmi — Understand the philosophy
- Core vs. template — What pgmi gives you, and what you own
- Highlights — Ten distinctive capabilities, grounded in code
- Session API — Learn the session API
- Trade-offs — Understand the honest costs
Migrating from another tool?
- Coming from other tools — Flyway, Liquibase, psql migration guides
- Quickstart — See pgmi in action
Writing deploy.sql?
- deploy.sql guide — Patterns cookbook (data ingestion, environment branching, multi-phase)
- Session API — Views, columns, and functions reference
Setting up production?
- Connections — Connection architecture (cloud auth, SSL, poolers)
- Security — Secrets and CI/CD patterns
- CI/CD — Deploy from GitHub Actions and other pipelines
- Production — Performance and rollback strategies
- Databricks Lakebase — Connect, deploy from a bundle job, test on a branch
- CLI reference — All flags and exit codes
Adding tests?
- Testing
—
CALL pgmi_test()and fixtures
Using the basic template?
- Basic template — Two layers, the run-once ledger and the test gate
- Testing
—
CALL pgmi_test()and fixtures
Using the advanced template?
- Advanced template overview — What the application stack ships and what you can remove
- MCP overview — Expose your deployed application to AI assistants
- Upgrading — Take template fixes into a project you have changed
Working with a coding agent?
- AI assistant support
—
pgmi serve,pgmi ai contract, and the project’sAGENTS.mdand skills
Articles#
Deployment
- Test PostgreSQL migrations before COMMIT : where the test gate sits, after lint and rehearsal
- Your ALTER TABLE Is Fast. The Queue Behind It Is Not.
: bounded lock waits and phased deploys; runnable in
examples/lock-safe-deploy/ - Your Transaction Boundary Belongs in the Program, Not the Filename : transactions decided in deploy.sql
- Your Migration Numbers Are a Distributed Counter Without Coordination
: a pull-request check on
pgmi_plan_viewrejects duplicate numbers before merge - Your Deployment Is a PostgreSQL Program : the deployment as code you can read and test
Testing and data
- Scenario-Tree Testing in PostgreSQL : several outcomes from one setup, each branch isolated by savepoints
- From Seed Scripts to Desired-State Reference Data
: reference data validated, diffed and reconciled from a file; runnable in
examples/seed-demo/
Application design
- The Request Becomes a Transaction : API tests inside the deploy transaction
- AI agents write PostgreSQL like Python : the handler discipline that keeps agent-written PL/pgSQL correct
Quick Answers#
| Question | Answer |
|---|---|
| Which view should I use? | pgmi_plan_view for deployment, pgmi_source_view for introspection — see Session API |
| How do I access CLI parameters? | current_setting('pgmi.key', true) — see Session API |
| How do I run tests? | CALL pgmi_test() in deploy.sql — see Testing |
| What’s the difference between templates? | Minimal = a deploy.sql loop and one file: the mechanism, bare. Basic = two layers: run-once tables, and views and functions re-run on every deploy, behind a test gate. Advanced = a full, tested PostgreSQL application stack (one handler registry → REST+RPC+MCP+OpenAPI, RLS auth, transaction policy, audit trails) — more infrastructure, not a higher safety tier. Basic and advanced are both production-capable; see Choose a template |
| How do I filter which files run? | Join pgmi_plan_view to pgmi_source_view, require is_sql_file, then add your path filter — see Session API |
| What exit codes does pgmi use? | 0=success, 13=SQL error, etc. — see CLI reference |
All Documentation#
Getting Started#
- Quickstart — Your first deployment (install, configure, deploy, verify)
- Why pgmi — When pgmi’s approach makes sense (and when it doesn’t)
- Core vs. template — The boundary between pgmi core and your scaffolded project
- Highlights — Ten distinctive pgmi capabilities, grounded in code and guides
- Coming from other tools — Migration guides from Flyway, Liquibase, and raw psql
- Choose a template — Minimal, basic and advanced compared: who each is for and what each ships
- Basic template — Two layers, the run-once ledger and the test gate
Reference#
- CLI reference — Complete CLI reference (commands, flags, exit codes, error messages)
- Configuration — pgmi.yaml schema and precedence rules
- Session API
— Session views and functions (
pg_temp.pgmi_*)
Guides#
- deploy.sql guide — deploy.sql authoring patterns (data ingestion, environment branching, multi-phase)
- Connections — Connection architecture (cloud auth, SSL, poolers, IaC)
- Trade-offs — Honest limitations and who should use pgmi
Features#
- Testing — Database testing with savepoint isolation and deploy gates
- Script metadata — Script tracking with UUIDs, idempotency, sort keys
- Security — Secrets handling and CI/CD patterns
Operations#
- CI/CD — Deploy from GitHub Actions and other pipelines
- Production — Performance, rollback strategies, monitoring
- Databricks Lakebase — Credentials, bundle jobs, the advanced template, a test gate on a branch
Advanced template (code you own)#
These pages document application code scaffolded by pgmi init --template advanced — a complete PostgreSQL application stack, not a pgmi core feature. The generated SQL and gateways become code you own, to keep, change or replace. Start at the capability tour
.
- MCP overview — What the MCP support scaffolds, what you operate, and where to start
- Client guides — Generate typed clients from your deployment’s OpenAPI contract
- Transaction policy — Per-route isolation floor, read-only declaration, DEFERRABLE derivation, fail-closed enforcement, replica-safe hint
- Run the MCP gateway — Start the reference gateway, connect an AI client, and operate it in production
- MCP handlers — Authoring MCP tool/resource/prompt handlers
- MCP protocol — JSON-RPC wire protocol and session lifecycle
- MCP SQL API — SQL functions powering the MCP gateway
- Login transport contract — What the web server in front of the database must do: OIDC sign-in, the session cookie and headers, logout
- Upgrading — Take template fixes into a project you have changed, and move from v0.13 to v0.14
- Trade-offs — The advanced template is a real program you maintain
- Semantic MCP curation — Optional extension to the MCP gateway: surface the relevant tool subset by embedding similarity (for tool-overload scale)
AI Integration#
pgmi ai # Overview for AI assistants
pgmi ai contract # Session API contract (views/functions)pgmi serve offers pgmi’s commands as MCP tools for coding agents (not the advanced template’s runtime MCP). Projects from --template basic or --template advanced carry their own AGENTS.md and skills in .agents/skills/; minimal writes none.
See CLI.md#pgmi-ai
for details.