Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/mssql/server:2017-latest
FROM mcr.microsoft.com/mssql/server:2022-latest
ARG ACCEPT_EULA=Y
ENV ACCEPT_EULA=N
ARG SA_PASSWORD=IMISuserP@s
Expand All @@ -7,6 +7,7 @@ ENV DB_USER_PASSWORD=IMISuserP@s
ENV DB_NAME=IMIS
ENV DB_USER=IMISUser
ENV INIT_MODE=empty
USER root
RUN mkdir -p /app
COPY script/* /app/
COPY sql /app/sql
Expand Down
20 changes: 12 additions & 8 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/sqlcmd -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
data=$($SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -C -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/sqlcmd -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 -C -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/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "CREATE DATABASE $DB_NAME"
$SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -C -Q "CREATE DATABASE $DB_NAME"

if [ "$INIT_MODE" = "demo" ]; then
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -i output/fullDemoDatabase.sql -d $DB_NAME | grep . | uniq -c
if [[ "$INIT_MODE" = "demo" ]]; then
$SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -C -i output/fullDemoDatabase.sql -d $DB_NAME | grep . | uniq -c
else
/opt/mssql-tools/bin/sqlcmd -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 -C -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/sqlcmd -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 -C -Q "EXEC sp_changedbowner '$DB_USER'" -d $DB_NAME
else
echo "database already existing, nothing to do"
fi
Expand Down