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

DB_CONNECTION_STRING="${1:-}"

if [ -z "$DB_CONNECTION_STRING" ]; then
  echo "Usage: $0 <db-connection-string>" >&2
  exit 1
fi

if ! command -v psql >/dev/null 2>&1; then
  echo "psql is required." >&2
  exit 1
fi

echo "Checking admin seed..."
psql "$DB_CONNECTION_STRING" -Atc "SELECT username FROM admin_users WHERE username = 'admin';" | grep -qx 'admin'
echo "Checking schema migrations..."
psql "$DB_CONNECTION_STRING" -Atc "SELECT 1 FROM schema_migrations WHERE version = '003';" >/dev/null
echo "Admin seed validation passed."
