Skip to content

Commit 2918c03

Browse files
SashkoMarchukclaude
andcommitted
fix(cpb): replace A && B || C with explicit if-then-else (SC2015)
Refactor schema grant error handling from fragile `cmd && echo || { ... }` to proper if/then/else. Prevents false error-path execution if echo fails. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dc7f468 commit 2918c03

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

scripts/cpb/setup-db.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ EOSQL
8585
# but we attempt it for forward-compatibility with PG15+ where it IS required.
8686
# temporal cannot grant on public schema in PG14 (owned by postgres), so we
8787
# handle the error gracefully.
88-
SCHEMA_GRANT_ERR=$(PGPASSWORD="${TEMPORAL_PASS}" psql -v ON_ERROR_STOP=1 \
88+
if SCHEMA_GRANT_ERR=$(PGPASSWORD="${TEMPORAL_PASS}" psql -v ON_ERROR_STOP=1 \
8989
-h "$PGHOST" -p "$PGPORT" -U "$TEMPORAL_USER" -d "$CPB_DB" \
90-
-c "GRANT ALL ON SCHEMA public TO \"${N8N_USER}\";" 2>&1) && \
91-
echo " Schema grant on public: OK" || {
90+
-c "GRANT ALL ON SCHEMA public TO \"${N8N_USER}\";" 2>&1); then
91+
echo " Schema grant on public: OK"
92+
else
9293
if echo "$SCHEMA_GRANT_ERR" | grep -qi "permission denied\|must be owner"; then
9394
echo " Schema grant on public: skipped (not needed on PG14 — PUBLIC has CREATE by default)"
9495
echo " NOTE: After upgrading to PG15+, re-run this script or grant manually:"
@@ -98,7 +99,7 @@ SCHEMA_GRANT_ERR=$(PGPASSWORD="${TEMPORAL_PASS}" psql -v ON_ERROR_STOP=1 \
9899
echo " $SCHEMA_GRANT_ERR" >&2
99100
exit 1
100101
fi
101-
}
102+
fi
102103

103104
echo ""
104105
echo "CPB database setup complete."

0 commit comments

Comments
 (0)