{"id":45679634,"url":"https://github.com/pgplex/pgschema","last_synced_at":"2026-03-01T18:00:39.278Z","repository":{"id":298277792,"uuid":"998434422","full_name":"pgplex/pgschema","owner":"pgplex","description":"Terraform-style, declarative schema migration CLI for Postgres","archived":false,"fork":false,"pushed_at":"2026-02-23T15:12:03.000Z","size":4714,"stargazers_count":794,"open_issues_count":7,"forks_count":29,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-02-23T22:51:39.290Z","etag":null,"topics":["cicd","cli","ddl","devops","gitops","multi-tenant","postgres","postgresql","schema","schema-change","schema-diff","schema-migration","schema-migrations","terraform"],"latest_commit_sha":null,"homepage":"https://www.pgschema.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pgplex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-08T15:50:01.000Z","updated_at":"2026-02-23T18:17:22.000Z","dependencies_parsed_at":"2025-12-29T13:07:07.811Z","dependency_job_id":null,"html_url":"https://github.com/pgplex/pgschema","commit_stats":null,"previous_names":["pgschema/pgschema","pgplex/pgschema"],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/pgplex/pgschema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgplex%2Fpgschema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgplex%2Fpgschema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgplex%2Fpgschema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgplex%2Fpgschema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgplex","download_url":"https://codeload.github.com/pgplex/pgschema/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgplex%2Fpgschema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29977966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-01T16:35:47.903Z","status":"ssl_error","status_checked_at":"2026-03-01T16:35:44.899Z","response_time":124,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cicd","cli","ddl","devops","gitops","multi-tenant","postgres","postgresql","schema","schema-change","schema-diff","schema-migration","schema-migrations","terraform"],"created_at":"2026-02-24T14:00:36.872Z","updated_at":"2026-03-01T18:00:39.261Z","avatar_url":"https://github.com/pgplex.png","language":"Go","readme":"\u003e [!NOTE]\n\u003e pgplex: Modern Developer Stack for Postgres - [pgconsole](https://github.com/pgplex/pgconsole) · [pgtui](https://github.com/pgplex/pgtui) · **pgschema** · [pgparser](https://github.com/pgplex/pgparser)\n\u003e\n\u003e Brought to you by [Bytebase](https://www.bytebase.com/), open-source database DevSecOps platform.\n\n![light-banner](https://raw.githubusercontent.com/pgplex/pgschema/main/docs/logo/light.png#gh-light-mode-only)\n![dark-banner](https://raw.githubusercontent.com/pgplex/pgschema/main/docs/logo/dark.png#gh-dark-mode-only)\n\n\u003ca href=\"https://www.star-history.com/#pgplex/pgschema\u0026Date\"\u003e\n \u003cpicture\u003e\n   \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://api.star-history.com/svg?repos=pgplex/pgschema\u0026type=Date\u0026theme=dark\" /\u003e\n   \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://api.star-history.com/svg?repos=pgplex/pgschema\u0026type=Date\" /\u003e\n   \u003cimg alt=\"Star History Chart\" src=\"https://api.star-history.com/svg?repos=pgplex/pgschema\u0026type=Date\" /\u003e\n \u003c/picture\u003e\n\u003c/a\u003e\n\n**pgschema** is a CLI tool that brings Terraform-style declarative schema migration to PostgreSQL. Instead of writing migration files by hand, you declare the desired schema state and pgschema generates the migration plan automatically.\n\n```\npgschema dump → edit schema.sql → pgschema plan → pgschema apply\n```\n\n- **Dump**: Extract the current database schema as SQL files\n- **Plan**: Diff your edited schema against the live database, generate migration DDL\n- **Apply**: Execute with concurrent change detection, transaction-adaptive execution, and lock timeout control\n\n## Why pgschema\n\n### State-based, not migration-file-based\n\nTools like Flyway and Liquibase require you to write and number migration files manually. pgschema works like Terraform: you declare what the schema *should look like*, and it figures out the SQL to get there. No migration history table, no manual sequencing.\n\n### Deep Postgres support\n\npgschema is Postgres-only, which means it handles Postgres-specific objects that generic tools skip: row-level security policies, partitioned tables, partial indexes, constraint triggers, identity columns, domain types, default privileges, and column-level grants. See the full list [below](#supported-schema-objects).\n\n### No shadow database required\n\nMost state-based tools spin up a temporary \"shadow\" database to validate migrations. pgschema uses an embedded Postgres instance internally and cleans up after itself — no extra infrastructure needed.\n\n### When to choose pgschema\n\n- You want a fully free and open-source tool with no feature gating\n- You want to version-control your schema as plain SQL and apply changes declaratively\n- You need Postgres-specific features (RLS, partitioning, complex triggers) tracked in migrations\n- You want migration validation without provisioning a separate shadow database\n- You want a plan/preview step before applying changes, like `terraform plan`\n- You're migrating from a manual SQL workflow and want structure without an ORM\n\n### How it compares\n\n| | pgschema | Flyway / Liquibase | Atlas |\n|---|---|---|---|\n| **Pricing** | **Free and open source (Apache 2.0)** | Free tier; advanced features paid | Free tier; advanced features paid |\n| Workflow | State-based (desired state) | Migration-file-based | State-based |\n| Database support | PostgreSQL only | Multi-database | Multi-database |\n| Postgres-specific objects | Auto-detected and diffed (RLS, partitioning, triggers, …) | You write the migration SQL manually | Auto-detected and diffed |\n| Shadow database | Not required | Not required | Required by default |\n| Migration history table | Not required | Required | Not required |\n\n### Why is it free?\n\nFair question. We have no current plans to charge for pgschema.\n\npgschema is sponsored by [Bytebase](https://www.bytebase.com), a commercial database DevSecOps platform. Bytebase covers the needs of teams that require controls beyond schema migration — data access control, data masking, audit logging, and multi-database management across an organization.\n\nSee more details in the [introduction blog post](https://www.pgschema.com/blog/pgschema-postgres-declarative-schema-migration-like-terraform).\n\nWatch in action:\n\n[![asciicast](https://asciinema.org/a/vXHygDMUkGYsF6nmz2h0ONEQC.svg)](https://asciinema.org/a/vXHygDMUkGYsF6nmz2h0ONEQC)\n\n## Supported Schema Objects\n\npgschema covers all the schema objects developers use in real-world Postgres applications, across versions 14-18:\n\n| Object | Key Features |\n|--------|-------------|\n| **Tables** | Columns, identity/generated columns, partitioning (RANGE/LIST/HASH), LIKE clauses, inline and table-level constraints |\n| **Constraints** | Primary keys, foreign keys (with ON DELETE/ON UPDATE), unique, check, NOT VALID, DEFERRABLE |\n| **Indexes** | Regular, UNIQUE, partial, functional/expression; all methods (btree, hash, gist, spgist, gin, brin); CONCURRENTLY |\n| **Views** | CREATE OR REPLACE, dependency-ordered migrations |\n| **Materialized Views** | WITH [NO] DATA, indexes on materialized views |\n| **Functions** | IN/OUT/INOUT parameters with defaults, SETOF/TABLE return types, SECURITY DEFINER, IMMUTABLE/STABLE/VOLATILE, STRICT |\n| **Procedures** | IN/OUT/INOUT parameters with defaults, all procedural languages |\n| **Triggers** | BEFORE/AFTER/INSTEAD OF, INSERT/UPDATE/DELETE/TRUNCATE, ROW/STATEMENT level, WHEN conditions, constraint triggers, REFERENCING OLD/NEW TABLE |\n| **Sequences** | START WITH, INCREMENT BY, MINVALUE/MAXVALUE, CYCLE, CACHE, OWNED BY |\n| **Types** | ENUM (add values in-place), composite types |\n| **Domains** | Base type, DEFAULT, NOT NULL, named and anonymous CHECK constraints |\n| **Policies** | Row-level security (RLS), PERMISSIVE/RESTRICTIVE, ALL/SELECT/INSERT/UPDATE/DELETE commands, USING/WITH CHECK expressions, ENABLE/DISABLE/FORCE ROW LEVEL SECURITY |\n| **Privileges** | GRANT/REVOKE for tables (including column-level), sequences, functions, procedures, types/domains; WITH GRANT OPTION |\n| **Default Privileges** | ALTER DEFAULT PRIVILEGES for tables, sequences, functions, types |\n| **Comments** | COMMENT ON for tables, columns, views, materialized views, functions, procedures, indexes |\n\nSee [Unsupported](https://www.pgschema.com/syntax/unsupported) for objects that are explicitly out of scope.\n\n## Installation\n\nVisit https://www.pgschema.com/installation\n\n\u003e [!NOTE]\n\u003e Windows is not supported. Please use WSL (Windows Subsystem for Linux) or a Linux VM.\n\n## Getting help\n\n- [Docs](https://www.pgschema.com)\n- [GitHub issues](https://github.com/pgplex/pgschema/issues)\n\n## Quick example\n\n### Step 1: Dump schema\n\n```bash\n# Dump current schema\n$ PGPASSWORD=testpwd1 pgschema dump \\\n    --host localhost \\\n    --db testdb \\\n    --user postgres \\\n    --schema public \u003e schema.sql\n```\n\n### Step 2: Edit schema\n\n```bash\n# Edit schema file declaratively\n--- a/schema.sql\n+++ b/schema.sql\n@@ -12,5 +12,6 @@\n\n CREATE TABLE IF NOT EXISTS users (\n     id SERIAL PRIMARY KEY,\n-    username varchar(50) NOT NULL UNIQUE\n+    username varchar(50) NOT NULL UNIQUE,\n+    age INT NOT NULL\n );\n```\n\n### Step 3: Generate plan\n\n```bash\n$ PGPASSWORD=testpwd1 pgschema plan \\\n    --host localhost \\\n    --db testdb \\\n    --user postgres \\\n    --schema public \\\n    --file schema.sql \\\n    --output-human stdout \\\n    --output-json plan.json\n\nPlan: 1 to modify.\n\nSummary by type:\n  tables: 1 to modify\n\nTables:\n  ~ users\n    + age (column)\n\nTransaction: true\n\nDDL to be executed:\n--------------------------------------------------\n\nALTER TABLE users ADD COLUMN age integer NOT NULL;\n```\n\n### Step 4: Apply plan with confirmation\n\n```bash\n# Or use --auto-approve to skip confirmation\n$ PGPASSWORD=testpwd1 pgschema apply \\\n    --host localhost \\\n    --db testdb \\\n    --user postgres \\\n    --schema public \\\n    --plan plan.json\n\nPlan: 1 to modify.\n\nSummary by type:\n  tables: 1 to modify\n\nTables:\n  ~ users\n    + age (column)\n\nTransaction: true\n\nDDL to be executed:\n--------------------------------------------------\n\nALTER TABLE users ADD COLUMN age integer NOT NULL;\n\nDo you want to apply these changes? (yes/no): yes\n\nApplying changes...\nChanges applied successfully!\n```\n\n## LLM / AI Integration\n\npgschema is designed to work well in AI-assisted workflows:\n\n- **[llms.txt](https://www.pgschema.com/llms.txt)** — concise machine-readable summary of pgschema capabilities\n- **[llms-full.txt](https://www.pgschema.com/llms-full.txt)** — full documentation in a single file optimized for LLM context windows\n\nThese files follow the [llms.txt standard](https://llmstxt.org/) and are suitable for including in agent tool definitions, RAG pipelines, or system prompts when building AI-assisted database tooling.\n\n![_](https://raw.githubusercontent.com/pgplex/pgschema/main/docs/images/copy-page.webp)\n\n## Development\n\n\u003e [!NOTE] \u003e **For external contributors**: If you require any features, please create a GitHub issue to discuss first instead of creating a PR directly.\n\n### Build\n\n```bash\ngit clone https://github.com/pgplex/pgschema.git\ncd pgschema\ngo mod tidy\ngo build -o pgschema .\n```\n\n### Run tests\n\n```bash\n# Run unit tests only\ngo test -short -v ./...\n\n# Run all tests including integration tests (uses Postgres testcontainers with Docker)\ngo test -v ./...\n```\n\n## Sponsor\n\n[Bytebase](https://www.bytebase.com?utm_sourcepgschema) - open source, web-based database DevSecOps platform.\n\n\u003ca href=\"https://www.bytebase.com?utm_sourcepgschema\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/pgplex/pgschema/main/docs/images/bytebase.webp\" /\u003e\u003c/a\u003e\n","funding_links":[],"categories":["\u003ca name=\"Go\"\u003e\u003c/a\u003eGo","Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgplex%2Fpgschema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgplex%2Fpgschema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgplex%2Fpgschema/lists"}