fix(ps-cache-kotlin): use psql -c instead of heredoc for schema setup#125
fix(ps-cache-kotlin): use psql -c instead of heredoc for schema setup#125slayerjain merged 1 commit intomainfrom
Conversation
docker exec ... psql -f- <<'SQL' doesn't work reliably because docker exec doesn't forward stdin from heredocs by default. Use psql -c "..." which works in all shells. Also add sleep 3 to wait for Postgres readiness. Signed-off-by: slayerjain <shubhamkjain@outlook.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Updates the standalone setup instructions for the ps-cache-kotlin demo so schema setup works reliably when run via docker exec, and adds a short wait after starting Postgres.
Changes:
- Replace
docker exec ... psql -f- <<'SQL'heredoc withpsql -c "..."to avoid stdin/heredoc issues. - Add a delay after
docker runto give Postgres time to start before running schema/seed commands.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| -p 5432:5432 postgres:16 | ||
|
|
||
| # Wait for Postgres to be ready | ||
| sleep 3 |
There was a problem hiding this comment.
Using a fixed sleep 3 for Postgres readiness is flaky (startup time varies by machine). Consider waiting on pg_isready in a loop (similar to the docker-compose healthcheck in ps-cache-kotlin/docker-compose.yml) so the README steps are deterministic.
| sleep 3 | |
| until docker exec pg-demo pg_isready -U postgres -d testdb >/dev/null 2>&1; do | |
| sleep 1 | |
| done |
| docker exec pg-demo psql -U postgres -d testdb -f- <<'SQL' | ||
| CREATE SCHEMA IF NOT EXISTS travelcard; | ||
| CREATE TABLE IF NOT EXISTS travelcard.travel_account ( | ||
| docker exec pg-demo psql -U postgres -d testdb -c " |
There was a problem hiding this comment.
psql defaults to continuing after statement errors and can still exit with status 0, which can make these setup commands look successful even when schema/seed failed. Consider adding -v ON_ERROR_STOP=1 (and optionally -X) to make failures fail fast for users copying the README commands.
| docker exec pg-demo psql -U postgres -d testdb -c " | |
| docker exec pg-demo psql -X -v ON_ERROR_STOP=1 -U postgres -d testdb -c " |
Summary
The
docker exec ... psql -f- <<'SQL'heredoc in the README doesn't work becausedocker execdoesn't forward stdin from heredocs by default. Replaced withpsql -c "..."which works in all shells.Also added
sleep 3afterdocker runto wait for Postgres readiness before running schema setup.Test plan