Adopting pgmold
Use pgmold dump to create a baseline from a live database, then manage all future changes through SQL files.
Create a baseline
Section titled “Create a baseline”# Export current database schema to SQLpgmold dump -d postgres://localhost/mydb -o schema/baseline.sql
# For specific schemas onlypgmold dump -d postgres://localhost/mydb --target-schemas public,auth -o schema/baseline.sql
# Split into multiple files by object typepgmold dump -d postgres://localhost/mydb --split -o schema/The --split option creates separate files for extensions, types, sequences, tables, functions, views, triggers, and policies.
After this, your schema files match the database exactly and pgmold plan shows zero operations.
Workflow after baseline
Section titled “Workflow after baseline”- Make changes by editing the SQL schema files
- Preview with
pgmold plan -s sql:schema/ -d postgres://localhost/mydb - Apply with
pgmold apply -s sql:schema/ -d postgres://localhost/mydb
Integrating with existing migration systems
Section titled “Integrating with existing migration systems”pgmold is declarative — it computes diffs and applies directly. To maintain compatibility with an existing migration system:
# Generate a numbered migration file automaticallypgmold migrate \ -s sql:schema/ \ -d postgres://localhost/mydb \ --migrations ./migrations \ --name "add_email_column"# Creates: migrations/0044_add_email_column.sql
# Or manually capture outputpgmold diff --from sql:current.sql --to sql:schema/ > migrations/0044_my_change.sqlThe migrate command auto-detects the next migration number. Use pgmold for diffing while keeping your existing migration runner.