rc-migration-tests/ef-migration/infrastructure/sql-server/setup.sh

52 lines
1.2 KiB
Bash

#!/bin/bash
# Start SQL Server
/opt/mssql/bin/sqlservr &
# Wait for SQL Server to start
echo "Waiting for SQL Server to start..."
sleep 30s
# Initialize database
for i in {1..50};
do
sqlcmd -S localhost -U sa -P $SA_PASSWORD -Q "SELECT 1" &> /dev/null
if [ $? -eq 0 ]
then
echo "SQL Server is ready"
break
else
echo "SQL Server is not ready yet..."
sleep 1
fi
done
# Run the initialization script
echo "Running initialization script..."
sqlcmd -S localhost -U sa -P $SA_PASSWORD -i /usr/src/app/init.sql
if [ $? -ne 0 ]; then
echo "Error executing initialization script"
exit 1
fi
# Run all schema scripts in the schemas directory
echo "Running schema scripts..."
for f in /usr/src/app/schemas/*.sql
do
echo "Processing $f..."
sqlcmd -S localhost -U sa -P $SA_PASSWORD -i "$f" -b
if [ $? -ne 0 ]; then
echo "Error executing schema script $f"
exit 1
fi
# Verify schema creation
sqlcmd -S localhost -U sa -P $SA_PASSWORD -Q "SELECT name FROM sys.schemas WHERE name IN ('fp', 'fw', 'int', 'ob')" -h -1
done
echo "All scripts executed. SQL Server is ready."
# Keep container running
while true; do
sleep 1
done