#!/bin/bash
# Wait for SQL Server to boot up (adjust sleep if needed)
echo "Waiting for SQL Server to start..."
sleep 20s

# Run the three SQL files using sqlcmd
# -S: Server, -U: User, -P: Password (passed via ENV)
echo "Applying SQL files..."

for migration in $(ls . | grep -E '\.sql$')
do
    echo "Applying $migration."
    /opt/mssql-tools/bin/sqlcmd -D $DSN_PASSWORD -i $migration.sql
done

echo "Database initialization complete."

# Keep the container alive by bringing the background process to the foreground
wait