Adjust setup.sh file to work with inline go statements

This commit is contained in:
Ubuntu 2025-02-04 21:17:16 +00:00
parent 50eae904e4
commit 89b19e7f62
13 changed files with 81 additions and 39 deletions

View File

@ -12,6 +12,7 @@ services:
- ACCEPT_EULA=Y
- MSSQL_PID=Express
- SA_PASSWORD=YourStrong@Passw0rd
- DROP_DATABASE=${DROP_DATABASE:-false}
volumes:
- sqlserver_data:/var/opt/mssql
deploy:

View File

@ -5,6 +5,7 @@ FROM mcr.microsoft.com/mssql/server:2022-latest
ENV ACCEPT_EULA=Y \
MSSQL_PID=Express \
SA_PASSWORD=YourStrong@Passw0rd \
DROP_DATABASE=false \
PATH="/opt/mssql-tools/bin:${PATH}"
# Install sqlcmd utility

View File

@ -21,6 +21,45 @@ do
fi
done
# Check if we should drop the database
if [ "${DROP_DATABASE,,}" = "true" ]; then
echo "DROP_DATABASE is true. Attempting to drop database..."
sqlcmd -S localhost -U sa -P $SA_PASSWORD -Q "
IF EXISTS (SELECT 1 FROM sys.databases WHERE name = 'st-database')
BEGIN
ALTER DATABASE [st-database] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE [st-database];
END"
if [ $? -eq 0 ]; then
echo "Database dropped successfully."
else
echo "Error dropping database"
exit 1
fi
fi
# Check if database already exists and has tables
echo "Checking if database is already initialized..."
DB_INITIALIZED=$(sqlcmd -S localhost -U sa -P $SA_PASSWORD -Q "
IF EXISTS (
SELECT 1
FROM sys.databases
WHERE name = 'st-database'
AND EXISTS (
SELECT 1
FROM st-database.sys.tables
WHERE name = 'AMAssumptionView'
)
)
SELECT 1
ELSE
SELECT 0" -h -1)
if [ "$DB_INITIALIZED" = "1" ]; then
echo "Database st-database already exists and is initialized. Skipping setup."
else
echo "Database needs initialization. Starting setup..."
# Create st-database if it doesn't exist
echo "Creating st-database if it doesn't exist..."
sqlcmd -S localhost -U sa -P $SA_PASSWORD -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = 'st-database') CREATE DATABASE [st-database]"
@ -62,6 +101,7 @@ do
done
echo "All scripts executed. SQL Server is ready."
fi
# Keep container running
while true; do