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

HOST="${DB_HOST:-db}"
PORT="${DB_PORT:-3306}"
USER="${DB_USER:-scmedia}"
PASS="${DB_PASS:-changeme}"

for i in $(seq 1 60); do
  if mysqladmin ping -h"${HOST}" -P"${PORT}" -u"${USER}" -p"${PASS}" --silent; then
    exit 0
  fi
  sleep 1
done

echo "DB not ready after 60s" >&2
exit 1
