pgmt — PostgreSQL Schema-as-Code
Database-first development for PostgreSQL Manage schema like code, deploy through explicit migrations
pgmt is a PostgreSQL migration tool that lets you develop your schema like software code — edit database objects directly, see changes immediately, then generate explicit migrations for production deployment.
Key Benefits
- Code-like Development: Edit views, functions, triggers, and grants like source code — pgmt handles drop/recreate automatically
- Explicit Control: Review generated migrations before deployment, not after
- Full PostgreSQL Support: Triggers, functions, enums, arrays, JSON, extensions, grants — not just tables
- Team Friendly: Schema files show intent, migrations show deployment steps
- Production Safe: Shadow databases, dependency ordering, sectioned migrations
Quick Start
Install pgmt:
Initialize your project:
# New project
# From existing database
Development workflow:
# 1. Edit schema files like code
# 2. Apply immediately to dev database
# 3. Generate migration when ready
# 4. Deploy to production
Documentation
- Quick Start — Get up and running
- Adopt Existing Database — Import existing schema with baselines
- Why Schema-as-Code? — The declarative + explicit approach
- Schema Organization — Multi-file organization and
-- require:syntax - CLI Reference — All commands and options
PostgreSQL Support
Core Objects: Tables, Views, Functions, Triggers, Indexes, Constraints, Custom Types, Sequences, Schemas, Extensions Advanced Features: Grants & Privileges, Row-Level Security, Comments, Complex Constraints, All Index Types, Function Overloading PostgreSQL-Specific: ENUMs, Arrays, JSON/JSONB, Exclusion Constraints, Partial Indexes, Expression Indexes
See the complete feature matrix for details.
Role & Permissions Management
pgmt manages database object privileges (GRANT/REVOKE) but not roles themselves — create roles using your preferred tools (SQL, Terraform, etc.), then define grants in schema files.
See the Roles & Permissions Guide.
Roadmap
Near-term: Advanced function features, smart rename detection, materialized views Long-term: Schema visualization, migration templates
See the complete roadmap.
Development & Contributing
# Quick setup (one-time)
# Run tests
# Test against specific PostgreSQL version
DATABASE_URL=
# Build from source
SQLX_OFFLINE=true
See the contributing guide for more details.
Community & Support
- Documentation — Guides and reference
- GitHub Discussions — Questions and patterns
- GitHub Issues — Bug reports and feature requests
License
MIT License — see LICENSE for details.