Skip to content

Commit

Permalink
2022
Browse files Browse the repository at this point in the history
  • Loading branch information
delcroip authored Aug 29, 2024
1 parent a2a98dc commit 328f532
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/mssql/server:2019-latest
FROM mcr.microsoft.com/mssql/server:2022-latest
ARG ACCEPT_EULA=Y
ENV ACCEPT_EULA=N
ARG SA_PASSWORD=IMISuserP@s
Expand All @@ -13,5 +13,4 @@ COPY script/* /app/
COPY sql /app/sql
WORKDIR /app
RUN chmod a+x /app/*.sh
USER mssql
CMD /bin/bash ./entrypoint.sh
16 changes: 10 additions & 6 deletions script/run-initialization.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,35 @@
# Wait to be sure that SQL Server came up
sleep 60s

MSSQL_TOOLS_BASE="/opt/mssql-tools"
MSSQL_TOOLS_VERSION=$(ls -d ${MSSQL_TOOLS_BASE}* 2>/dev/null | sort -V | tail -n 1 | sed "s|${MSSQL_TOOLS_BASE}||")
SQLCMD_PATH="${MSSQL_TOOLS_BASE}${MSSQL_TOOLS_VERSION}/bin/sqlcmd"


# DATABSE initialisation

echo "Database initialisaton"
# if the table does not exsit it will create the table

# get "1" if the database exist : tr get only the integer, cut only the first integer (the second is the number of row affected)
data=$(/opt/mssql-tools/bin/sqlcmd18 -S localhost -U SA -P $SA_PASSWORD -Q "SELECT COUNT(*) FROM master.dbo.sysdatabases WHERE name = N'$DB_NAME'" | tr -dc '0-9'| cut -c1 )
data=$($SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -Q "SELECT COUNT(*) FROM master.dbo.sysdatabases WHERE name = N'$DB_NAME'" | tr -dc '0-9'| cut -c1 )
if [[ ${data} -eq "0" ]]; then
echo 'download full demo database'
echo 'create database user'
/opt/mssql-tools/bin/sqlcmd18 -S localhost -U SA -P $SA_PASSWORD -Q "CREATE LOGIN $DB_USER WITH PASSWORD='${SA_PASSWORD}', CHECK_POLICY = OFF"
$SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -Q "CREATE LOGIN $DB_USER WITH PASSWORD='${SA_PASSWORD}', CHECK_POLICY = OFF"
echo "merging files"
./concatenate_files.sh
echo 'create database'
#/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "DROP DATABASE IF EXISTS $DB_NAME"
/opt/mssql-tools/bin/sqlcmd18 -S localhost -U SA -P $SA_PASSWORD -Q "CREATE DATABASE $DB_NAME"
$SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -Q "CREATE DATABASE $DB_NAME"

if [[ "$INIT_MODE" = "demo" ]]; then
/opt/mssql-tools/bin/sqlcmd18 -S localhost -U SA -P $SA_PASSWORD -i output/fullDemoDatabase.sql -d $DB_NAME | grep . | uniq -c
$SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -i output/fullDemoDatabase.sql -d $DB_NAME | grep . | uniq -c
else
/opt/mssql-tools/bin/sqlcmd18 -S localhost -U SA -P $SA_PASSWORD -i output/fullEmptyDatabase.sql -d $DB_NAME | grep . | uniq -c
$SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -i output/fullEmptyDatabase.sql -d $DB_NAME | grep . | uniq -c
fi
echo ' give to the user the access to the database'
/opt/mssql-tools/bin/sqlcmd18 -S localhost -U SA -P $SA_PASSWORD -Q "EXEC sp_changedbowner '$DB_USER'" -d $DB_NAME
$SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -Q "EXEC sp_changedbowner '$DB_USER'" -d $DB_NAME
else
echo "database already existing, nothing to do"
fi
Expand Down

0 comments on commit 328f532

Please sign in to comment.