Files
backend/database/wait-for-postgres.sh
T
Ali Reza bb59d5e9ba Initial commit: Meshkee CMS API
NestJS backend with Prisma, Docker Compose for Postgres/Redis, and deploy docs for the production VM.
2026-07-21 17:52:36 +03:30

30 lines
970 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
CONTAINER="${POSTGRES_CONTAINER:-meshkee-postgres}"
DB_USER="${POSTGRES_USER:-meshkee}"
DB_NAME="${POSTGRES_DB:-meshkee_cms}"
MAX_ATTEMPTS="${WAIT_MAX_ATTEMPTS:-60}"
SLEEP_SECONDS="${WAIT_SLEEP_SECONDS:-1}"
echo "Waiting for PostgreSQL in container '$CONTAINER'..."
for ((attempt = 1; attempt <= MAX_ATTEMPTS; attempt++)); do
if docker exec "$CONTAINER" pg_isready -U "$DB_USER" -d "$DB_NAME" >/dev/null 2>&1; then
if docker exec "$CONTAINER" psql -U "$DB_USER" -d "$DB_NAME" -tAc \
"SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'users'" \
2>/dev/null | grep -q 1; then
echo "PostgreSQL is ready."
exit 0
fi
fi
if [[ "$attempt" -eq "$MAX_ATTEMPTS" ]]; then
echo "PostgreSQL did not become ready within ${MAX_ATTEMPTS}s." >&2
echo "Check: docker compose ps && docker compose logs postgres" >&2
exit 1
fi
sleep "$SLEEP_SECONDS"
done