Baseline Management
Baselines are complete SQL snapshots of your schema at a point in time. They’re optional - pgmt can reconstruct state from your migration chain - but useful for performance when migration chains get long.
When You Need Baselines
Section titled “When You Need Baselines”Importing an existing database: When you run pgmt init against a database that already has objects, you create a baseline to establish the starting point. See Adopt Existing Database.
Long migration chains: After 50+ migrations, new environment setup gets slow. A baseline lets pgmt skip replaying the entire chain.
Major releases: Mark stable points in your schema history for faster rollback or environment provisioning.
How pgmt Works Without Baselines
Section titled “How pgmt Works Without Baselines”When you clone a repo and run pgmt migrate new, pgmt needs to know the current schema state to generate the right diff. Without a baseline, it reconstructs by applying all migrations in order:
Clone repo → Apply V1 → Apply V2 → ... → Apply V50 → Compare to schema files → Generate V51With a baseline:
Clone repo → Load baseline → Compare to schema files → Generate V51Both produce the same result. Baselines just make it faster.
This is why migrations stay incremental: A new team member cloning the repo, editing schema files, and running migrate new gets an ALTER statement - not a full schema recreation. pgmt reconstructs the chain to understand what already exists.
Commands
Section titled “Commands”Create a baseline:
# Standalonepgmt baseline create
# With a migrationpgmt migrate new "v2.0 release" --create-baselineList baselines:
pgmt baseline listClean up old baselines:
# Keep the 5 most recentpgmt baseline clean --keep=5
# Preview what would be deletedpgmt baseline clean --keep=3 --dry-runConfiguration
Section titled “Configuration”migration: create_baselines_by_default: false # Recommended - create on-demandBy default, migrate new doesn’t create baselines. Use --create-baseline when you want one.
Troubleshooting
Section titled “Troubleshooting”Migration recreates existing objects:
This happens when pgmt can’t determine the current state. Create a baseline to establish it:
pgmt baseline createBaseline inconsistent with schema:
Verify your schema files match the database:
pgmt apply --dry-run