Skip to content

Commit 166bf13

Browse files
authored
Merge pull request openimis#177 from openimis/feature/2019
use mssql 2022
2 parents 64fda4d + b03f894 commit 166bf13

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/mssql/server:2017-latest
1+
FROM mcr.microsoft.com/mssql/server:2022-latest
22
ARG ACCEPT_EULA=Y
33
ENV ACCEPT_EULA=N
44
ARG SA_PASSWORD=IMISuserP@s
@@ -7,6 +7,7 @@ ENV DB_USER_PASSWORD=IMISuserP@s
77
ENV DB_NAME=IMIS
88
ENV DB_USER=IMISUser
99
ENV INIT_MODE=empty
10+
USER root
1011
RUN mkdir -p /app
1112
COPY script/* /app/
1213
COPY sql /app/sql

script/run-initialization.sh

+12-8
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,35 @@
44
# Wait to be sure that SQL Server came up
55
sleep 60s
66

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

812
# DATABSE initialisation
913

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

1317
# get "1" if the database exist : tr get only the integer, cut only the first integer (the second is the number of row affected)
14-
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 )
15-
if [ ${data} -eq "0" ]; then
18+
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 )
19+
if [[ ${data} -eq "0" ]]; then
1620
echo 'download full demo database'
1721
echo 'create database user'
18-
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "CREATE LOGIN $DB_USER WITH PASSWORD='${SA_PASSWORD}', CHECK_POLICY = OFF"
22+
$SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -C -Q "CREATE LOGIN $DB_USER WITH PASSWORD='${SA_PASSWORD}', CHECK_POLICY = OFF"
1923
echo "merging files"
2024
./concatenate_files.sh
2125
echo 'create database'
2226
#/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "DROP DATABASE IF EXISTS $DB_NAME"
23-
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "CREATE DATABASE $DB_NAME"
27+
$SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -C -Q "CREATE DATABASE $DB_NAME"
2428

25-
if [ "$INIT_MODE" = "demo" ]; then
26-
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -i output/fullDemoDatabase.sql -d $DB_NAME | grep . | uniq -c
29+
if [[ "$INIT_MODE" = "demo" ]]; then
30+
$SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -C -i output/fullDemoDatabase.sql -d $DB_NAME | grep . | uniq -c
2731
else
28-
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -i output/fullEmptyDatabase.sql -d $DB_NAME | grep . | uniq -c
32+
$SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -C -i output/fullEmptyDatabase.sql -d $DB_NAME | grep . | uniq -c
2933
fi
3034
echo ' give to the user the access to the database'
31-
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q "EXEC sp_changedbowner '$DB_USER'" -d $DB_NAME
35+
$SQLCMD_PATH -S localhost -U SA -P $SA_PASSWORD -C -Q "EXEC sp_changedbowner '$DB_USER'" -d $DB_NAME
3236
else
3337
echo "database already existing, nothing to do"
3438
fi

0 commit comments

Comments
 (0)