1515 pgschema-plan-single :
1616 runs-on : ubuntu-latest
1717
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+
1836 steps :
1937 - name : Checkout code
2038 uses : actions/checkout@v4
@@ -27,29 +45,50 @@ jobs:
2745 - name : Install pgschema
2846 run : go install github.com/pgschema/pgschema@latest
2947
48+ - name : Setup baseline schema from main branch
49+ run : |
50+ # Checkout main branch to get baseline schema
51+ git fetch origin main
52+ git checkout origin/main -- singlefile/schema.sql || {
53+ echo "::error::Could not checkout schema.sql from main branch"
54+ exit 1
55+ }
56+
57+ # Copy main branch schema to temporary location
58+ cp singlefile/schema.sql /tmp/main_schema.sql
59+
60+ # Restore current branch schema
61+ git checkout HEAD -- singlefile/schema.sql
62+
63+ # Apply main branch schema to establish baseline database state
64+ echo "::group::Applying baseline schema"
65+ pgschema apply \
66+ --auto-approve \
67+ --host localhost \
68+ --port 5432 \
69+ --db testdb \
70+ --user postgres \
71+ --file /tmp/main_schema.sql \
72+ || echo "::warning::Failed to apply baseline schema"
73+ echo "::endgroup::"
74+
3075 - name : Run pgschema plan
3176 id : plan
3277 run : |
33- # Run pgschema plan and capture output
78+ # Run pgschema plan
3479 PLAN_OUTPUT=$(pgschema plan \
35- --host "${{ secrets.DB_HOST }}" \
36- --port "${{ secrets.DB_PORT }}" \
37- --db "${{ secrets.DB_NAME }}" \
38- --user "${{ secrets.DB_USER }}" \
80+ --debug \
81+ --host localhost \
82+ --port 5432 \
83+ --db testdb \
84+ --user postgres \
3985 --file "${{ github.workspace }}/singlefile/schema.sql" \
4086 --format human 2>&1)
4187
42- # Escape special characters for GitHub Actions
43- PLAN_OUTPUT="${PLAN_OUTPUT//'%'/'%25'}"
44- PLAN_OUTPUT="${PLAN_OUTPUT//$'\n'/'%0A'}"
45- PLAN_OUTPUT="${PLAN_OUTPUT//$'\r'/'%0D'}"
46-
4788 # Set output
4889 echo "plan<<EOF" >> $GITHUB_OUTPUT
4990 echo "$PLAN_OUTPUT" >> $GITHUB_OUTPUT
5091 echo "EOF" >> $GITHUB_OUTPUT
51- env :
52- PGPASSWORD : ${{ secrets.DB_PASSWORD }}
5392
5493 - name : Comment PR
5594 uses : actions/github-script@v7
61100 // Decode the escaped output
62101 const decodedOutput = decodeURIComponent(planOutput);
63102
64- const body = `## pgschema Plan Output (Single File)
103+ const body = `## pgschema Plan Output
65104
66105 <details>
67106 <summary>Click to expand plan details</summary>
83122
84123 const botComment = comments.find(comment =>
85124 comment.user.type === 'Bot' &&
86- comment.body.includes('pgschema Plan Output (Single File) ')
125+ comment.body.includes('pgschema Plan Output')
87126 );
88127
89128 if (botComment) {
0 commit comments