Terraform-style declarative schema migrations for PostgreSQL: dump, edit, plan, apply
open sourceApache-2.0free
A CLI for declarative schema migrations on PostgreSQL, from the pgplex toolchain backed by Bytebase. You dump the live schema as SQL files, edit them to the state you want, and pgschema plans the DDL by diffing against the database, then applies it with concurrent change detection and lock timeout control. There's no migration history table and no shadow database: it validates with an embedded Postgres instance. Being Postgres-only, it tracks objects generic tools skip, such as row-level security policies, partitioned tables, partial indexes, constraint triggers and column-level grants. Apache 2.0, with no feature gating.
Problems it solves
- generate Postgres migrations from my edited schema file like terraform plan
- track row-level security policies and grants in my schema migrations
- preview the exact DDL before changing a production Postgres schema
Features
- dump a Postgres schema as SQL files
- plan migration DDL by diffing a schema file against the live database
- apply with concurrent change detection and lock timeouts
- row-level security, partitioning, triggers and grants tracked
- no shadow database (embedded Postgres)
- docs for use from a coding agent
Alternatives
The same job
These do what pgschema does.
- Atlas Database schema as code: plan, lint, test and apply schema migrations, like Terraform for databases
- sqldef Idempotent schema management in plain SQL for MySQL, PostgreSQL, SQLite and SQL Server
- Reylo Import .sql files into TypeScript with types inferred from your live database, plus SQL-first migrations
- Reshape An easy-to-use, zero-downtime schema migration tool for Postgres
- pgroll Zero-downtime, reversible schema migrations for Postgres
- Flyway Versioned SQL database migrations for 50+ databases, open source with Redgate's enterprise editions
