#!/usr/bin/env bash
set -euo pipefail

if ! docker ps --filter "name=kb-postgres" --filter "status=running" | grep -qw "kb-postgres"; then
    echo "[FAIL] kb-postgres container is not running"
    exit 1
fi

if ! docker exec kb-postgres pg_isready -U kb -d kb > /dev/null 2>&1; then
    echo "[FAIL] kb-postgres is not accepting connections"
    exit 1
fi

echo "[OK] kb-postgres is healthy"
exit 0
