Skip to content

fix(ps-cache-kotlin): use psql -c instead of heredoc for schema setup#125

Merged
slayerjain merged 1 commit intomainfrom
fix/ps-cache-kotlin-heredoc
Apr 16, 2026
Merged

fix(ps-cache-kotlin): use psql -c instead of heredoc for schema setup#125
slayerjain merged 1 commit intomainfrom
fix/ps-cache-kotlin-heredoc

Conversation

@slayerjain
Copy link
Copy Markdown
Member

Summary

The docker exec ... psql -f- <<'SQL' heredoc in the README doesn't work because docker exec doesn't forward stdin from heredocs by default. Replaced with psql -c "..." which works in all shells.

Also added sleep 3 after docker run to wait for Postgres readiness before running schema setup.

Test plan

  • Run the standalone setup commands from the README on a fresh machine

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>
Copilot AI review requested due to automatic review settings April 16, 2026 20:58
@slayerjain slayerjain merged commit 631bb30 into main Apr 16, 2026
4 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with psql -c "..." to avoid stdin/heredoc issues.
  • Add a delay after docker run to give Postgres time to start before running schema/seed commands.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ps-cache-kotlin/README.md
-p 5432:5432 postgres:16

# Wait for Postgres to be ready
sleep 3
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
sleep 3
until docker exec pg-demo pg_isready -U postgres -d testdb >/dev/null 2>&1; do
sleep 1
done

Copilot uses AI. Check for mistakes.
Comment thread ps-cache-kotlin/README.md
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 "
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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 "

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants