pgmt 0.4.4

PostgreSQL migration tool that keeps your schema files as the source of truth
Documentation

pgmt — PostgreSQL Schema-as-Code

CI Crates.io License: MIT

Edit database objects like code. pgmt tracks dependencies, applies changes instantly, and generates production-ready migrations.

Status: Alpha — API may change. Production use requires careful evaluation.

pgmt demo

One function changed. pgmt detected 3 dependent views, dropped them in the right order, applied the update, and recreated everything — automatically.

Quick Start

cargo install pgmt

# Initialize (new project or from existing database)
pgmt init
pgmt init --dev-url postgres://localhost/my_existing_db

# Edit schema files, then apply to dev
pgmt apply

# Generate migration when ready to ship
pgmt migrate new "add user analytics"

# Deploy to production
pgmt migrate apply --target-url $PROD_DATABASE_URL

Watch Mode

Edit a schema file, save — your dev database updates instantly. No migration files during development, no manual dependency management. The database finally works like the rest of your development environment.

$ pgmt apply --watch
👀 Watching schema/ for changes...

  schema/functions/calculate_score.sql changed

📋 8 changes
   Drop view public.executive_dashboard
  ...
   Create view public.executive_dashboard

 Applied 8 changes

Production Migrations

When you're done iterating, pgmt migrate new generates an explicit SQL migration file. You review it, edit it if needed, and deploy it. Nothing touches production without your approval.

Multi-section migrations handle the hard stuff — concurrent indexes, data backfills, different timeouts — all in one file with per-section retries:

-- pgmt:section name="add_column" timeout="5s"
ALTER TABLE users ADD COLUMN verified BOOLEAN;

-- pgmt:section name="backfill" mode="autocommit" timeout="30m"
UPDATE users SET verified = false WHERE verified IS NULL;

-- pgmt:section name="add_index" mode="non-transactional" retry_attempts="10"
CREATE INDEX CONCURRENTLY idx_users_verified ON users(verified);

Documentation

Requirements

  • PostgreSQL 13+ (tested on 13–18)
  • Rust 1.74+ for building from source

Contributing

./scripts/test-setup.sh   # One-time setup
cargo test                 # Run tests

See the contributing guide for details.

License

MIT — see LICENSE.