#!/usr/bin/env bash # docker-dev cluster-seed entrypoint. Waits for the host containers to finish # their EF Core auto-migration (which creates the ServerCluster table), then # applies the idempotent seed script. # # Image: mcr.microsoft.com/mssql-tools (Debian + sqlcmd at /opt/mssql-tools18/bin). set -euo pipefail SQLCMD="/opt/mssql-tools18/bin/sqlcmd" SERVER="${SQL_HOST:-sql},1433" USER="${SQL_USER:-sa}" PASS="${SQL_PASSWORD:-OtOpcUa!Dev123}" DB="${SQL_DATABASE:-OtOpcUa}" run_sql() { "$SQLCMD" -S "$SERVER" -U "$USER" -P "$PASS" -d "$DB" -No -b -h -1 "$@" } echo "[cluster-seed] waiting for SQL Server to accept connections..." until run_sql -Q "SELECT 1" >/dev/null 2>&1; do sleep 2 done echo "[cluster-seed] SQL Server up." echo "[cluster-seed] waiting for $DB.ServerCluster (host containers must finish EF migration)..." until run_sql -Q "IF OBJECT_ID('dbo.ServerCluster') IS NULL THROW 50001, 'missing', 1; SELECT 1" >/dev/null 2>&1; do sleep 3 done echo "[cluster-seed] schema ready." echo "[cluster-seed] applying seed-clusters.sql..." run_sql -i /seed/seed-clusters.sql echo "[cluster-seed] done."