You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-5Lines changed: 34 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# pgschema GitHub Actions Example
2
2
3
-
This repository demonstrates how to use [pgschema](https://www.pgschema.com/) with GitHub Actions to automatically run schema migration plans on pull requests. It includes examples for both single-file and multi-file schema approaches.
3
+
This 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.
4
4
5
5
## Overview
6
6
@@ -11,8 +11,10 @@ This repository demonstrates how to use [pgschema](https://www.pgschema.com/) wi
11
11
12
12
Plan workflows automatically:
13
13
14
-
- Run `pgschema plan` when a PR modifies schema files
15
-
- Post the migration plan as a comment on the PR
14
+
- Run `pgschema plan --output-human stdout --output-json plan.json` when a PR modifies schema files
15
+
- Generate both human-readable output for PR comments and plan.json artifact for deployment
16
+
- Post the migration plan as a comment on the PR for team review
17
+
- Upload plan.json as a GitHub artifact for the apply workflow
16
18
- Update the comment if the PR is synchronized with new changes
17
19
18
20
### Apply Workflows (Merged Pull Requests)
@@ -22,11 +24,36 @@ Plan workflows automatically:
22
24
23
25
Apply workflows automatically:
24
26
25
-
- Run `pgschema apply` when pull requests are merged to main branch
26
-
- Use `--auto-approve` flag for automated deployment
27
+
- Download the plan.json artifact generated during the plan phase
28
+
- Run `pgschema apply --plan plan.json` using the pre-approved plan
29
+
- Validate database fingerprint to ensure no concurrent schema changes occurred
27
30
- Apply changes to a test PostgreSQL 17 container
28
31
- Comment on the PR with success or failure results and detailed logs
29
32
33
+
## Plan-Review-Apply Workflow Pattern
34
+
35
+
This implementation follows the [pgschema plan-review-apply pattern](https://www.pgschema.com/workflow/plan-review-apply) for safe database migrations:
36
+
37
+
### 1. Plan Phase (Pull Request)
38
+
39
+
- Generates detailed migration plan with `pgschema plan`
40
+
- Creates both human-readable output and plan.json artifact
41
+
- Team reviews the proposed changes in PR comments
42
+
- Plan.json is stored as GitHub artifact for later use
43
+
44
+
### 2. Review Phase (Pull Request Review)
45
+
46
+
- Team examines the migration plan for correctness and safety
0 commit comments