1+ name : pgschema Apply - Single File
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ paths :
8+ - ' singlefile/**'
9+ - ' .github/workflows/pgschema-singlefile-apply.yml'
10+
11+ permissions :
12+ contents : read
13+
14+ jobs :
15+ pgschema-apply-single :
16+ runs-on : ubuntu-latest
17+
18+ env :
19+ PGPASSWORD : postgres
20+
21+ services :
22+ postgres :
23+ image : postgres:17
24+ env :
25+ POSTGRES_PASSWORD : postgres
26+ POSTGRES_USER : postgres
27+ POSTGRES_DB : testdb
28+ options : >-
29+ --health-cmd pg_isready
30+ --health-interval 10s
31+ --health-timeout 5s
32+ --health-retries 5
33+ ports :
34+ - 5432:5432
35+
36+ steps :
37+ - name : Checkout code
38+ uses : actions/checkout@v4
39+
40+ - name : Setup Go
41+ uses : actions/setup-go@v5
42+ with :
43+ go-version : ' stable'
44+
45+ - name : Install pgschema
46+ run : go install github.com/pgschema/pgschema@latest
47+
48+ - name : Run pgschema apply
49+ id : apply
50+ run : |
51+ echo "::group::Applying schema changes"
52+
53+ # Run pgschema apply with auto-approve
54+ APPLY_OUTPUT=$(pgschema apply \
55+ --auto-approve \
56+ --debug \
57+ --host localhost \
58+ --port 5432 \
59+ --db testdb \
60+ --user postgres \
61+ --file "${{ github.workspace }}/singlefile/schema.sql" \
62+ --lock-timeout "30s" \
63+ --application-name "pgschema-github-action-apply" \
64+ --format human 2>&1)
65+
66+ APPLY_EXIT_CODE=$?
67+
68+ # Output the results
69+ echo "$APPLY_OUTPUT"
70+
71+ echo "::endgroup::"
72+
73+ # Set outputs for potential future use
74+ echo "output<<EOF" >> $GITHUB_OUTPUT
75+ echo "$APPLY_OUTPUT" >> $GITHUB_OUTPUT
76+ echo "EOF" >> $GITHUB_OUTPUT
77+
78+ echo "exit_code=$APPLY_EXIT_CODE" >> $GITHUB_OUTPUT
79+
80+ # Exit with the same code as pgschema
81+ exit $APPLY_EXIT_CODE
82+
83+ - name : Report Success
84+ if : success()
85+ run : |
86+ echo "✅ Schema changes applied successfully!"
87+ echo ""
88+ echo "Applied to database: testdb"
89+ echo "Application name: pgschema-github-action-apply"
90+ echo "Lock timeout: 30s"
91+
92+ - name : Report Failure
93+ if : failure()
94+ run : |
95+ echo "❌ Failed to apply schema changes!"
96+ echo ""
97+ echo "Please check the logs above for details."
98+ echo "Common issues:"
99+ echo "- Schema syntax errors"
100+ echo "- Database connection issues"
101+ echo "- Lock timeout exceeded"
102+ echo "- Incompatible schema changes"
0 commit comments