#!/bin/bash
# Run the three SQL files using sqlcmd
# -S: Server, -U: User, -P: Password (passed via ENV)
sleep 20


echo "Applying SQL files..."

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

echo "Database initialization complete."

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