Prerequisites
Before starting, ensure you have:- pgschema installed (see installation guide)
- Access to a PostgreSQL database (14+)
- Database credentials with appropriate permissions
Step 1: Dump Your Current Schema
First, let’s capture the current state of your database schema:schema.sql file containing your complete schema definition. Let’s look at what it contains:
schema.sql
The output is clean and developer-friendly, unlike the verbose output from
pg_dump.Step 2: Make Schema Changes
Now, let’s modify theschema.sql file to add new features. Edit the file to include:
schema.sql (modified)
Step 3: Generate Plan
plan.json and print the human-readable version to stdout:
plan.txt
Step 4: Apply Changes
When you’re ready to apply the changes:Alternative: Direct Apply
You can also skip the separate planning step and apply changes directly from the schema file:The two-phase workflow (plan then apply) is recommended for production environments where you want to review and save the plan before execution. Direct apply is convenient for development environments.
- Show you the migration plan
- Ask for confirmation (unless using
--auto-approve) - Apply the changes
- Report success or any errors

