Skip to content

Commit 57899f8

Browse files
committed
chore: debug apply
1 parent 6499d74 commit 57899f8

File tree

1 file changed

+112
-4
lines changed

1 file changed

+112
-4
lines changed

.github/workflows/pgschema-singlefile-apply.yml

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,86 @@ jobs:
4545
- name: Install pgschema
4646
run: go install github.com/pgschema/pgschema@latest
4747

48+
- name: Verify database connection
49+
run: |
50+
echo "::group::Verifying database connection"
51+
echo "Testing database connection..."
52+
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d testdb -c "SELECT version();"
53+
echo "Database connection successful!"
54+
echo "::endgroup::"
55+
4856
- name: Load baseline schema
4957
run: |
5058
echo "::group::Loading baseline schema to emulate remote database"
51-
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d testdb -f baseline.sql
59+
echo "Loading baseline.sql..."
60+
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d testdb -f baseline.sql -v ON_ERROR_STOP=1
61+
echo "Baseline schema loaded successfully!"
62+
echo "::endgroup::"
63+
64+
- name: Verify baseline schema
65+
run: |
66+
echo "::group::Verifying baseline schema was loaded"
67+
echo "Checking tables..."
68+
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d testdb -c "\dt"
69+
echo ""
70+
echo "Checking functions..."
71+
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d testdb -c "\df"
72+
echo ""
73+
echo "Checking types..."
74+
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d testdb -c "\dT"
75+
echo "::endgroup::"
76+
77+
- name: Debug schema file
78+
run: |
79+
echo "::group::Debugging schema file"
80+
echo "Schema file path: ${{ github.workspace }}/singlefile/schema.sql"
81+
echo "Schema file exists: $(test -f "${{ github.workspace }}/singlefile/schema.sql" && echo "YES" || echo "NO")"
82+
if [ -f "${{ github.workspace }}/singlefile/schema.sql" ]; then
83+
echo "Schema file size: $(wc -l < "${{ github.workspace }}/singlefile/schema.sql") lines"
84+
echo "First 10 lines of schema file:"
85+
head -10 "${{ github.workspace }}/singlefile/schema.sql"
86+
else
87+
echo "ERROR: Schema file not found!"
88+
echo "Contents of singlefile directory:"
89+
ls -la "${{ github.workspace }}/singlefile/" || echo "singlefile directory not found"
90+
fi
91+
echo "::endgroup::"
92+
93+
- name: Test pgschema plan first
94+
run: |
95+
echo "::group::Testing pgschema plan (dry run)"
96+
echo "Running pgschema plan to check for issues..."
97+
98+
set +e # Don't exit on error
99+
PLAN_OUTPUT=$(pgschema plan \
100+
--debug \
101+
--host localhost \
102+
--port 5432 \
103+
--db testdb \
104+
--user postgres \
105+
--file "${{ github.workspace }}/singlefile/schema.sql" \
106+
--format human 2>&1)
107+
PLAN_EXIT_CODE=$?
108+
set -e # Re-enable exit on error
109+
110+
echo "Plan exit code: $PLAN_EXIT_CODE"
111+
echo "Plan output:"
112+
echo "$PLAN_OUTPUT"
113+
114+
if [ $PLAN_EXIT_CODE -ne 0 ]; then
115+
echo "::error::pgschema plan failed - this indicates an issue with the schema file or database connection"
116+
fi
52117
echo "::endgroup::"
53118
54119
- name: Run pgschema apply
55120
id: apply
56121
run: |
57122
echo "::group::Applying schema changes"
58-
123+
echo "Running pgschema apply with detailed logging..."
124+
125+
# Enable detailed error reporting
126+
set -x # Show commands as they execute
127+
59128
# Run pgschema apply with auto-approve
60129
APPLY_OUTPUT=$(pgschema apply \
61130
--auto-approve \
@@ -70,8 +139,11 @@ jobs:
70139
--format human 2>&1)
71140
72141
APPLY_EXIT_CODE=$?
142+
143+
set +x # Disable command tracing
73144
74-
# Output the results
145+
echo "Apply exit code: $APPLY_EXIT_CODE"
146+
echo "Apply output:"
75147
echo "$APPLY_OUTPUT"
76148
77149
echo "::endgroup::"
@@ -83,6 +155,23 @@ jobs:
83155
84156
echo "exit_code=$APPLY_EXIT_CODE" >> $GITHUB_OUTPUT
85157
158+
# If failed, provide additional debugging
159+
if [ $APPLY_EXIT_CODE -ne 0 ]; then
160+
echo "::group::Additional debugging for failure"
161+
echo "pgschema version:"
162+
pgschema --version || echo "Could not get pgschema version"
163+
echo ""
164+
echo "Current working directory:"
165+
pwd
166+
echo ""
167+
echo "Environment variables:"
168+
env | grep -E "(PG|POSTGRES)" || echo "No PostgreSQL environment variables found"
169+
echo ""
170+
echo "Database connection test:"
171+
PGPASSWORD=postgres psql -h localhost -p 5432 -U postgres -d testdb -c "SELECT current_database(), current_user;" || echo "Database connection failed"
172+
echo "::endgroup::"
173+
fi
174+
86175
# Exit with the same code as pgschema
87176
exit $APPLY_EXIT_CODE
88177
@@ -100,4 +189,23 @@ jobs:
100189
run: |
101190
echo "❌ Failed to apply schema changes!"
102191
echo ""
103-
echo "Please check the logs above for details."
192+
echo "🔍 Debugging Information:"
193+
echo "- Check the 'Debug schema file' step to verify the schema file exists"
194+
echo "- Check the 'Verify database connection' step for connection issues"
195+
echo "- Check the 'Verify baseline schema' step to ensure baseline loaded correctly"
196+
echo "- Check the 'Test pgschema plan first' step for schema validation issues"
197+
echo "- Check the 'Run pgschema apply' step for detailed error output"
198+
echo ""
199+
echo "📋 Common issues:"
200+
echo "- Schema syntax errors in singlefile/schema.sql"
201+
echo "- Database connection issues (host, port, credentials)"
202+
echo "- Lock timeout exceeded (another process holding locks)"
203+
echo "- Incompatible schema changes (breaking changes to existing structure)"
204+
echo "- Missing schema file or incorrect file path"
205+
echo "- Baseline schema conflicts with target schema"
206+
echo ""
207+
echo "💡 Next steps:"
208+
echo "1. Review the detailed logs in the failed steps above"
209+
echo "2. Test the schema file locally with pgschema plan"
210+
echo "3. Verify the schema syntax is valid PostgreSQL"
211+
echo "4. Check for conflicts between baseline.sql and singlefile/schema.sql"

0 commit comments

Comments
 (0)