|
4 | 4 | # Wait to be sure that SQL Server came up
|
5 | 5 | sleep 60s
|
6 | 6 |
|
| 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 | + |
7 | 11 |
|
8 | 12 | # DATABSE initialisation
|
9 | 13 |
|
10 | 14 | echo "Database initialisaton"
|
11 | 15 | # if the table does not exsit it will create the table
|
12 | 16 |
|
13 | 17 | # 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 |
16 | 20 | echo 'download full demo database'
|
17 | 21 | 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" |
19 | 23 | echo "merging files"
|
20 | 24 | ./concatenate_files.sh
|
21 | 25 | echo 'create database'
|
22 | 26 | #/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" |
24 | 28 |
|
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 |
27 | 31 | 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 |
29 | 33 | fi
|
30 | 34 | 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 |
32 | 36 | else
|
33 | 37 | echo "database already existing, nothing to do"
|
34 | 38 | fi
|
|
0 commit comments