Skip to main content
The Plan-Review-Apply workflow separates change planning from execution, creating a safety gate that prevents unintended database modifications:
  1. Plan - Generate a detailed migration plan showing exactly what will change
  2. Review - Examine the plan for correctness, safety, and business impact
  3. Apply - Execute the reviewed and approved changes
This separation allows for thorough validation and team collaboration before making any database changes.

Workflow

Step 1: Plan Your Changes

Generate a migration plan to see what changes pgschema will make:

Step 2: Review the Plan

Examine the generated plan carefully:

Step 3: Apply the Changes

Once the plan is approved, apply the changes:

Detect Concurrent Changes with Fingerprinting

Fingerprinting ensures that the exact changes you reviewed in the plan are the changes that get applied, maintaining the integrity of the Plan-Review-Apply workflow.
pgschema uses a fingerprinting mechanism to ensure consistency between the plan and apply phases. When you run pgschema plan, it captures a snapshot (fingerprint) of the current database schema state. Later, when you run pgschema apply, it verifies that the database hasn’t changed since the plan was generated. This prevents scenarios where:
  • Someone else modified the database between your plan and apply
  • The database drifted from the expected state
  • Multiple developers are making concurrent schema changes

How Fingerprinting Works

  1. During Plan: pgschema calculates a fingerprint of the current database schema
  2. Plan Storage: The fingerprint is embedded in the plan
  3. During Apply: pgschema recalculates the database fingerprint and compares it with the stored one
  4. Safety Check: If fingerprints don’t match, apply is aborted with an error

Fingerprint Validation Example

When fingerprint mismatches occur, you need to regenerate the plan:

Online DDL

pgschema automatically generates migration plans that use online DDL strategies to minimize downtime. When possible, operations like index creation, constraint addition, and schema modifications are executed using PostgreSQL’s concurrent and non-blocking features. For detailed information about online DDL patterns and strategies, see the Online DDL documentation.