Skip to content

Commit 4becdde

Browse files
fastapi-sqlalchemy-pg-catalog: tighten flow.sh + init.sql per Copilot review
flow.sh: - set -Eeuo pipefail so curl/other failures actually fail the script. - Track readiness explicitly; exit 1 with a clear message if the app never reaches /health within READY_TIMEOUT_S (default 60s) instead of silently falling through and proceeding against a dead app. - curl -fsS for the readiness probe and the endpoint calls so HTTP failures propagate as exit codes (the previous `curl -sS ... && echo` shape silenced non-2xx responses). init.sql: - Replace `INSERT ... ON CONFLICT DO NOTHING` with `INSERT ... SELECT WHERE NOT EXISTS`. The model has no UNIQUE constraint on name, so ON CONFLICT had nothing to fire on; this form is genuinely idempotent on re-runs against an existing volume. Refs Copilot review on #102. Signed-off-by: Akash Kumar <meakash7902@gmail.com>
1 parent 61a61e6 commit 4becdde

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
#!/usr/bin/env bash
22
# Drives traffic during keploy record. Hits both endpoints.
3-
set -uo pipefail
3+
set -Eeuo pipefail
44

55
APP_HOST_PORT="${APP_HOST_PORT:-8123}"
66
APP_URL="${APP_URL:-http://localhost:${APP_HOST_PORT}}"
7+
READY_TIMEOUT_S="${READY_TIMEOUT_S:-60}"
78

8-
echo "[flow] waiting for app at $APP_URL ..."
9-
for i in $(seq 1 60); do
10-
if curl -sf "$APP_URL/health" > /dev/null 2>&1; then
9+
echo "[flow] waiting for app at $APP_URL (ceiling ${READY_TIMEOUT_S}s) ..."
10+
ready=0
11+
for i in $(seq 1 "$READY_TIMEOUT_S"); do
12+
if curl -fsS --max-time 1 "$APP_URL/health" > /dev/null 2>&1; then
1113
echo "[flow] app ready after ${i}s"
14+
ready=1
1215
break
1316
fi
1417
sleep 1
1518
done
1619

20+
if [ "$ready" -ne 1 ]; then
21+
echo "[flow] ERROR: app never became ready at $APP_URL/health within ${READY_TIMEOUT_S}s" >&2
22+
exit 1
23+
fi
24+
1725
echo "[flow] GET /health"
18-
curl -sS "$APP_URL/health" && echo
26+
curl -fsS "$APP_URL/health"
27+
echo
1928

2029
echo "[flow] GET /projects"
21-
curl -sS "$APP_URL/projects" && echo
30+
curl -fsS "$APP_URL/projects"
31+
echo
2232

2333
echo "[flow] done"

fastapi-sqlalchemy-pg-catalog/init.sql

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@ CREATE TABLE IF NOT EXISTS project (
1212
name VARCHAR(100) NOT NULL
1313
);
1414

15-
INSERT INTO project (name) VALUES ('seed') ON CONFLICT DO NOTHING;
15+
-- Idempotent seed. `ON CONFLICT DO NOTHING` would only help with a
16+
-- UNIQUE/EXCLUSION constraint on name, which the SQLAlchemy model
17+
-- doesn't declare; use NOT EXISTS so re-running this script against
18+
-- an existing volume doesn't duplicate the row.
19+
INSERT INTO project (name)
20+
SELECT 'seed'
21+
WHERE NOT EXISTS (SELECT 1 FROM project WHERE name = 'seed');

0 commit comments

Comments
 (0)