Adjust database initialization logic
This commit is contained in:
parent
b32845f656
commit
b12cc774e2
@ -36,27 +36,20 @@ if [ "${DROP_DATABASE,,}" = "true" ]; then
|
||||
echo "Error dropping database"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if database already exists and has tables
|
||||
echo "Checking if database is already initialized..."
|
||||
echo "Checking if database is already initialized..."
|
||||
DB_INITIALIZED=$(sqlcmd -S localhost -U sa -P $SA_PASSWORD -h -1 -Q "
|
||||
DECLARE @DBExists BIT = 0;
|
||||
|
||||
# First check if database exists
|
||||
DB_EXISTS=$(sqlcmd -S localhost -U sa -P $SA_PASSWORD -h -1 -Q "
|
||||
IF EXISTS (SELECT 1 FROM sys.databases WHERE name = 'st-database')
|
||||
BEGIN
|
||||
-- Set the context to the target database
|
||||
EXEC('USE [st-database];
|
||||
IF EXISTS (SELECT 1 FROM sys.tables WHERE name = ''AMAssumptionView'')
|
||||
BEGIN
|
||||
SET @DBExists = 1;
|
||||
END');
|
||||
END;
|
||||
SELECT 1
|
||||
ELSE
|
||||
SELECT 0" | tr -d '[:space:]')
|
||||
|
||||
SELECT @DBExists;")
|
||||
echo "Database exists check result: '$DB_EXISTS'"
|
||||
|
||||
if [ "$DB_INITIALIZED" = "1" ]; then
|
||||
if [ "$DB_EXISTS" = "1" ]; then
|
||||
echo "Database st-database already exists and is initialized. Skipping setup."
|
||||
else
|
||||
echo "Database needs initialization. Starting setup..."
|
||||
@ -147,6 +140,8 @@ else
|
||||
rm -rf sql_objects
|
||||
echo "SQL object execution completed"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Keep container running
|
||||
while true; do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user