{"id":43035352,"url":"https://github.com/pgschema/github-actions-example","last_synced_at":"2026-01-31T08:17:33.406Z","repository":{"id":308140497,"uuid":"999490920","full_name":"pgschema/github-actions-example","owner":"pgschema","description":"GitHub Actions Example using pgschema","archived":false,"fork":false,"pushed_at":"2025-08-12T11:20:50.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-12T12:30:58.003Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PLpgSQL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pgschema.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-10T10:30:26.000Z","updated_at":"2025-08-12T11:20:54.000Z","dependencies_parsed_at":"2025-08-04T13:43:04.787Z","dependency_job_id":"0a809e41-b29d-421c-b15d-304f323f8267","html_url":"https://github.com/pgschema/github-actions-example","commit_stats":null,"previous_names":["pgschema/github-actions-example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pgschema/github-actions-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgschema%2Fgithub-actions-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgschema%2Fgithub-actions-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgschema%2Fgithub-actions-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgschema%2Fgithub-actions-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pgschema","download_url":"https://codeload.github.com/pgschema/github-actions-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pgschema%2Fgithub-actions-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28934969,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T07:49:44.436Z","status":"ssl_error","status_checked_at":"2026-01-31T07:49:34.274Z","response_time":128,"last_error":"SSL_read: 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":[],"created_at":"2026-01-31T08:17:32.874Z","updated_at":"2026-01-31T08:17:33.393Z","avatar_url":"https://github.com/pgschema.png","language":"PLpgSQL","readme":"# pgschema GitHub Actions Example\n\nThis repository demonstrates how to use [pgschema](https://www.pgschema.com/) with GitHub Actions to implement the **plan-review-apply workflow pattern** for safe database schema migrations. It includes examples for both single-file and multi-file schema approaches.\n\n## Overview\n\n### Plan Workflows (Pull Requests)\n\n- **Single File Plan** - Shows migration plan for single-file schemas\n- **Multi File Plan** - Shows migration plan for multi-file schemas\n\nPlan workflows automatically:\n\n- Run `pgschema plan --output-human stdout --output-json plan.json` when a PR modifies schema files\n- Generate both human-readable output for PR comments and plan.json artifact for deployment\n- Post the migration plan as a comment on the PR for team review\n- Upload plan.json as a GitHub artifact for the apply workflow\n- Update the comment if the PR is synchronized with new changes\n\n### Apply Workflows (Merged Pull Requests)\n\n- **Single File Apply** - Applies schema changes for single-file approach\n- **Multi File Apply** - Applies schema changes for multi-file approach\n\nApply workflows automatically:\n\n- Download the plan.json artifact generated during the plan phase using `dawidd6/action-download-artifact`\n- Run `pgschema apply --plan plan.json --auto-approve` using the pre-approved plan\n- Validate database fingerprint to ensure no concurrent schema changes occurred\n- Apply changes to a test PostgreSQL 17 container\n- Comment on the PR with success or failure results and detailed logs\n\n## Plan-Review-Apply Workflow Pattern\n\nThis implementation follows the [pgschema plan-review-apply pattern](https://www.pgschema.com/workflow/plan-review-apply) for safe database migrations:\n\n### 1. Plan Phase (Pull Request)\n\n- Generates detailed migration plan with `pgschema plan`\n- Creates both human-readable output and plan.json artifact\n- Team reviews the proposed changes in PR comments\n- Plan.json is stored as GitHub artifact for later use\n\n### 2. Review Phase (Pull Request Review)\n\n- Team examines the migration plan for correctness and safety\n- Considers business impact and potential risks\n- Approves or requests changes before merging\n\n### 3. Apply Phase (Merge to Main)\n\n- Downloads the exact plan.json that was reviewed using `dawidd6/action-download-artifact`\n- Applies using `pgschema apply --plan plan.json --auto-approve`\n- Fingerprint validation prevents concurrent schema changes\n- Ensures exactly what was planned is what gets applied\n\n## Setup\n\n### PostgreSQL 17 Test Container Setup\n\nThe workflows automatically set up a PostgreSQL 17 test container and load the baseline schema to emulate a remote database with existing schema. The `baseline.sql` file contains a complete schema.\n\n### Workflow Behavior\n\nEach workflow now:\n\n1. **Starts a clean PostgreSQL 17 container**\n2. **Loads baseline.sql** to simulate an existing remote database\n3. **Runs pgschema** against this baseline to generate migration plans or apply changes\n4. **Reports results** with detailed logging\n\nThis approach ensures that:\n\n- Migration plans show realistic diffs against existing schema\n- Apply operations work against a database with existing data structure\n- Tests validate changes in a production-like environment\n- Plans are generated and validated against the actual target database state\n- Fingerprint validation catches any concurrent schema modifications\n\n### GitHub Secrets\n\nNo secrets required! Both workflows start a PostgreSQL 17 test container for demonstration purposes, making them fully self-contained.\n\n### Schema Organization\n\n#### Single File Approach\n\n- Place your complete schema in `singlefile/schema.sql`. This is generated by `pgschema dump --host localhost --user postgres --password testpwd1 --db employee --file schema.sql`.\n- All tables, indexes, functions, and triggers in one file\n- Plan workflow: `.github/workflows/pgschema-singlefile-plan.yml`\n- Apply workflow: `.github/workflows/pgschema-singlefile-apply.yml`\n\n#### Multi File Approach\n\n- Place SQL files in the `multifile/` directory. This is generated by `pgschema dump --host localhost --user postgres --password testpwd1 --db employee --multi-file --file main.sql`\n- Uses `main.sql` as the entry point with psql `\\i` directives\n- Organize files by type in subdirectories (tables/, functions/, views/, etc.). Each file contains a specific database object\n- Plan workflow: `.github/workflows/pgschema-multifile-plan.yml`\n- Apply workflow: `.github/workflows/pgschema-multifile-apply.yml`\n\nFor more information, visit the [pgschema documentation](https://www.pgschema.com/).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgschema%2Fgithub-actions-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpgschema%2Fgithub-actions-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpgschema%2Fgithub-actions-example/lists"}