pgmi Documentation#

pgmi is a PostgreSQL-native deployment tool that loads your project files into session temp tables and lets your deploy.sql drive everything — transactions, execution order, and logic. These docs cover the session API, CLI, deployment patterns, testing, security, and operational guides.

The pgmi model: pgmi prepares one PostgreSQL session and hands control to your deploy.sql

New to pgmi? Start here:

  1. Quickstart — Deploy your first project
  2. Why pgmi — Understand the philosophy
  3. Core vs. template — What pgmi gives you, and what you own
  4. Highlights — What pgmi does that other tools can’t
  5. Session API — Learn the session API
  6. Trade-offs — Understand the honest costs

Migrating from another tool?

  1. Coming from other tools — Flyway, Liquibase, psql migration guides
  2. Quickstart — See pgmi in action

Writing deploy.sql?

  1. deploy.sql guide — Patterns cookbook (data ingestion, environment branching, multi-phase)
  2. Session API — Views, columns, and functions reference

Setting up production?

  1. Connections — Connection architecture (cloud auth, SSL, poolers)
  2. Security — Secrets and CI/CD patterns
  3. CI/CD — Deploy from GitHub Actions and other pipelines
  4. Production — Performance and rollback strategies
  5. CLI reference — All flags and exit codes

Adding tests?

  1. TestingCALL pgmi_test() and fixtures

Using the advanced template?

  1. Advanced template overview — The application stack and the basic/advanced boundary
  2. Script metadata — Script tracking with <pgmi-meta>
  3. MCP gateway — Expose your deployed application to AI assistants
  4. API keys — Authenticate callers of your generated APIs

Quick Answers#

QuestionAnswer
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?Basic = small, explicit migration scaffold. Advanced = ~19k lines of tested SQL application stack (one handler registry → REST+RPC+MCP+OpenAPI, RLS auth, transaction policy, audit trails) — more infrastructure, not a higher safety tier. Either is production-capable; see Quickstart and the capability tour
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

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

Advanced template (~19k lines 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, modify, or delete. Start at the capability tour .

  • MCP gateway — Expose your deployed application’s tools, resources, and prompts to AI assistants over HTTP
  • API keys — API key authentication for callers of your generated REST/RPC/MCP APIs
  • 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
  • MCP gateway — Gateway internals: routing, auth, transaction lifecycle, OpenAPI generation
  • 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
  • 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 skills             # List embedded skills
pgmi ai skill pgmi-sql     # Load SQL conventions

See CLI.md#pgmi-ai for details.