-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (94 loc) · 3.08 KB
/
pgschema-singlefile-apply.yml
File metadata and controls
116 lines (94 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: pgschema Apply - Single File
on:
push:
branches:
- main
paths:
- "singlefile/**"
- ".github/workflows/pgschema-singlefile-apply.yml"
permissions:
contents: read
jobs:
pgschema-apply-single:
runs-on: ubuntu-latest
env:
PGPASSWORD: postgres
services:
postgres:
image: postgres:17
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: testdb
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "stable"
- name: Install pgschema
run: go install github.com/pgschema/pgschema@latest
- name: Load baseline schema
run: |
echo "::group::Loading baseline schema to emulate remote database"
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d testdb -f baseline.sql
echo "::endgroup::"
- name: Run pgschema apply
id: apply
run: |
echo "::group::Applying schema changes"
echo "Running pgschema apply with detailed logging..."
# Enable detailed error reporting
set -x # Show commands as they execute
# Run pgschema apply with auto-approve
APPLY_OUTPUT=$(pgschema apply \
--auto-approve \
--debug \
--host localhost \
--port 5432 \
--db testdb \
--user postgres \
--file "${{ github.workspace }}/singlefile/schema.sql" \
--lock-timeout "30s" \
--application-name "pgschema-github-action-apply" \
2>&1)
APPLY_EXIT_CODE=$?
set +x # Disable command tracing
echo "Apply exit code: $APPLY_EXIT_CODE"
echo "Apply output:"
echo "$APPLY_OUTPUT"
echo "::endgroup::"
# Set outputs for potential future use
echo "output<<EOF" >> $GITHUB_OUTPUT
echo "$APPLY_OUTPUT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "exit_code=$APPLY_EXIT_CODE" >> $GITHUB_OUTPUT
# Exit with the same code as pgschema
exit $APPLY_EXIT_CODE
- name: Report Success
if: success()
run: |
echo "✅ Schema changes applied successfully!"
echo ""
echo "Applied to database: testdb"
echo "Application name: pgschema-github-action-apply"
echo "Lock timeout: 30s"
- name: Report Failure
if: failure()
run: |
echo "❌ Failed to apply schema changes!"
echo ""
echo "Please check the logs above for details."
echo "Common issues:"
echo "- Schema syntax errors"
echo "- Database connection issues"
echo "- Lock timeout exceeded"
echo "- Incompatible schema changes"