Skip to content

Commit

Permalink
[ODS-6579] Update path and flags for sqlcmd (#1187)
Browse files Browse the repository at this point in the history
  • Loading branch information
simpat-jesus authored Dec 6, 2024
1 parent 3ae8241 commit 9f00274
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
10 changes: 5 additions & 5 deletions Docker/ods-api-db-admin/ubuntu/mssql/setup-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ STATUS_SA=1
STATUS_USER=1
while [[ $STATUS_SA -ne 0 && $STATUS_USER -ne 0 ]]; do
>&2 echo "Waiting for server to be online... "
STATUS_SA=$(/opt/mssql-tools/bin/sqlcmd -W -h -1 -U sa -P "${SQLSERVER_PASSWORD}" -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" > /dev/null 2>&1 || echo 1)
STATUS_SA=$(/opt/mssql-tools18/bin/sqlcmd -C -W -h -1 -U sa -P "${SQLSERVER_PASSWORD}" -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" > /dev/null 2>&1 || echo 1)

STATUS_USER=$(/opt/mssql-tools/bin/sqlcmd -W -h -1 -U ${SQLSERVER_USER} -P "${SQLSERVER_PASSWORD}" -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" > /dev/null 2>&1 || echo 1)
STATUS_USER=$(/opt/mssql-tools18/bin/sqlcmd -C -W -h -1 -U ${SQLSERVER_USER} -P "${SQLSERVER_PASSWORD}" -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" > /dev/null 2>&1 || echo 1)

sleep 10
done

echo "Configuring user..."
# If conneciton fails, it means we already have configured logins, so we can redirect the error to /dev/null
/opt/mssql-tools/bin/sqlcmd -U sa -P "${SQLSERVER_PASSWORD}" -Q "
/opt/mssql-tools18/bin/sqlcmd -C -U sa -P "${SQLSERVER_PASSWORD}" -Q "
CREATE LOGIN ${SQLSERVER_USER} WITH PASSWORD = '${SQLSERVER_PASSWORD}';
CREATE USER ${SQLSERVER_USER} FOR LOGIN ${SQLSERVER_USER};
ALTER SERVER ROLE [sysadmin] ADD MEMBER ${SQLSERVER_USER};
Expand All @@ -29,7 +29,7 @@ echo "Configuring user..."
# If the Admin database is restored, we skip restoring it again
if [[ ! -f "/var/opt/mssql/data/EdFi_Admin.mdf" ]]; then
echo "Loading EdFi_Admin database from backup..."
/opt/mssql-tools/bin/sqlcmd -U ${SQLSERVER_USER} -P ${SQLSERVER_PASSWORD} -Q "
/opt/mssql-tools18/bin/sqlcmd -C -U ${SQLSERVER_USER} -P ${SQLSERVER_PASSWORD} -Q "
RESTORE DATABASE [EdFi_Admin] FROM DISK = N'/app/backups/EdFi_Admin.bak'
WITH MOVE 'EdFi_Admin' TO '/var/opt/mssql/data/EdFi_Admin.mdf',
MOVE 'EdFi_Admin_Log' TO '/var/opt/mssql/log/EdFi_Admin_log.ldf';"
Expand All @@ -38,7 +38,7 @@ fi
# If the Security database is restored, we skip restoring it again
if [[ ! -f "/var/opt/mssql/data/EdFi_Security.mdf" ]]; then
echo "Loading EdFi_Security Database from backup..."
/opt/mssql-tools/bin/sqlcmd -U ${SQLSERVER_USER} -P ${SQLSERVER_PASSWORD} -Q "
/opt/mssql-tools18/bin/sqlcmd -C -U ${SQLSERVER_USER} -P ${SQLSERVER_PASSWORD} -Q "
RESTORE DATABASE [EdFi_Security] FROM DISK = N'/app/backups/EdFi_Security.bak'
WITH MOVE 'EdFi_Security' TO '/var/opt/mssql/data/EdFi_Security.mdf',
MOVE 'EdFi_Security_Log' TO '/var/opt/mssql/log/EdFi_Security_log.ldf';"
Expand Down
8 changes: 4 additions & 4 deletions Docker/ods-api-db-ods-minimal/ubuntu/mssql/setup-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ STATUS_SA=1
STATUS_USER=1
while [[ $STATUS_SA -ne 0 && $STATUS_USER -ne 0 ]]; do
>&2 echo "Waiting for server to be online... "
STATUS_SA=$(/opt/mssql-tools/bin/sqlcmd -W -h -1 -U sa -P "${SQLSERVER_PASSWORD}" -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" > /dev/null 2>&1 || echo 1)
STATUS_SA=$(/opt/mssql-tools18/bin/sqlcmd -C -W -h -1 -U sa -P "${SQLSERVER_PASSWORD}" -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" > /dev/null 2>&1 || echo 1)

STATUS_USER=$(/opt/mssql-tools/bin/sqlcmd -W -h -1 -U ${SQLSERVER_USER} -P "${SQLSERVER_PASSWORD}" -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" > /dev/null 2>&1 || echo 1)
STATUS_USER=$(/opt/mssql-tools18/bin/sqlcmd -C -W -h -1 -U ${SQLSERVER_USER} -P "${SQLSERVER_PASSWORD}" -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" > /dev/null 2>&1 || echo 1)

sleep 10
done

echo "Configuring user..."
# If conneciton fails, it means we already have configured logins, so we can redirect the error to /dev/null
/opt/mssql-tools/bin/sqlcmd -U sa -P "${SQLSERVER_PASSWORD}" -Q "
/opt/mssql-tools18/bin/sqlcmd -C -U sa -P "${SQLSERVER_PASSWORD}" -Q "
CREATE LOGIN ${SQLSERVER_USER} WITH PASSWORD = '${SQLSERVER_PASSWORD}';
CREATE USER ${SQLSERVER_USER} FOR LOGIN ${SQLSERVER_USER};
ALTER SERVER ROLE [sysadmin] ADD MEMBER ${SQLSERVER_USER};
Expand All @@ -35,7 +35,7 @@ fi
# If the EdFi_Ods_Minimal_Template is restored, we skip restoring it again
if [[ ! -f "/var/opt/mssql/data/EdFi_Ods_Minimal_Template.mdf" ]]; then
echo "Loading EdFi_Ods_Minimal_Template database from backup..."
/opt/mssql-tools/bin/sqlcmd -U ${SQLSERVER_USER} -P ${SQLSERVER_PASSWORD} -Q "
/opt/mssql-tools18/bin/sqlcmd -C -U ${SQLSERVER_USER} -P ${SQLSERVER_PASSWORD} -Q "
RESTORE DATABASE [EdFi_Ods] FROM DISK = N'/app/backups/${MINIMAL_BACKUP}'
WITH MOVE 'EdFi_Ods_Populated_Template_Test' TO '/var/opt/mssql/data/EdFi_Ods_Minimal_Template.mdf',
MOVE 'EdFi_Ods_Populated_Template_Test_Log' TO '/var/opt/mssql/log/EdFi_Ods_Minimal_Template_log.ldf';"
Expand Down
10 changes: 5 additions & 5 deletions Docker/ods-api-db-ods-sandbox/ubuntu/mssql/setup-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ STATUS_SA=1
STATUS_USER=1
while [[ $STATUS_SA -ne 0 && $STATUS_USER -ne 0 ]]; do
>&2 echo "Waiting for server to be online... "
STATUS_SA=$(/opt/mssql-tools/bin/sqlcmd -W -h -1 -U sa -P "${SQLSERVER_PASSWORD}" -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" > /dev/null 2>&1 || echo 1)
STATUS_SA=$(/opt/mssql-tools18/bin/sqlcmd -C -W -h -1 -U sa -P "${SQLSERVER_PASSWORD}" -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" > /dev/null 2>&1 || echo 1)

STATUS_USER=$(/opt/mssql-tools/bin/sqlcmd -W -h -1 -U ${SQLSERVER_USER} -P "${SQLSERVER_PASSWORD}" -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" > /dev/null 2>&1 || echo 1)
STATUS_USER=$(/opt/mssql-tools18/bin/sqlcmd -C -W -h -1 -U ${SQLSERVER_USER} -P "${SQLSERVER_PASSWORD}" -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" > /dev/null 2>&1 || echo 1)

sleep 10
done

echo "Configuring user..."
# If conneciton fails, it means we already have configured logins, so we can redirect the error to /dev/null
/opt/mssql-tools/bin/sqlcmd -U sa -P "${SQLSERVER_PASSWORD}" -Q "
/opt/mssql-tools18/bin/sqlcmd -C -U sa -P "${SQLSERVER_PASSWORD}" -Q "
CREATE LOGIN ${SQLSERVER_USER} WITH PASSWORD = '${SQLSERVER_PASSWORD}';
CREATE USER ${SQLSERVER_USER} FOR LOGIN ${SQLSERVER_USER};
ALTER SERVER ROLE [sysadmin] ADD MEMBER ${SQLSERVER_USER};
Expand All @@ -37,7 +37,7 @@ fi
# If the EdFi_Ods_Minimal_Template is restored, we skip restoring it again
if [[ ! -f "/var/opt/mssql/data/EdFi_Ods_Minimal_Template.mdf" ]]; then
echo "Loading EdFi_Ods_Minimal_Template database from backup..."
/opt/mssql-tools/bin/sqlcmd -U ${SQLSERVER_USER} -P ${SQLSERVER_PASSWORD} -Q "
/opt/mssql-tools18/bin/sqlcmd -C -U ${SQLSERVER_USER} -P ${SQLSERVER_PASSWORD} -Q "
RESTORE DATABASE [EdFi_Ods_Minimal_Template] FROM DISK = N'/app/backups/${MINIMAL_BACKUP}'
WITH MOVE 'EdFi_Ods_Populated_Template_Test' TO '/var/opt/mssql/data/EdFi_Ods_Minimal_Template.mdf',
MOVE 'EdFi_Ods_Populated_Template_Test_Log' TO '/var/opt/mssql/log/EdFi_Ods_Minimal_Template_log.ldf';"
Expand All @@ -46,7 +46,7 @@ fi
# If the EdFi_Ods_Populated_Template is restored, we skip restoring it again
if [[ ! -f "/var/opt/mssql/data/EdFi_Ods_Populated_Template.mdf" ]]; then
echo "Loading EdFi_Ods_Populated_Template database from backup..."
/opt/mssql-tools/bin/sqlcmd -U ${SQLSERVER_USER} -P ${SQLSERVER_PASSWORD} -Q "
/opt/mssql-tools18/bin/sqlcmd -C -U ${SQLSERVER_USER} -P ${SQLSERVER_PASSWORD} -Q "
RESTORE DATABASE [EdFi_Ods_Populated_Template] FROM DISK = N'/app/backups/${POPULATED_BACKUP}'
WITH MOVE 'EdFi_Ods_Populated_Template_Test' TO '/var/opt/mssql/data/EdFi_Ods_Populated_Template.mdf',
MOVE 'EdFi_Ods_Populated_Template_Test_Log' TO '/var/opt/mssql/log/EdFi_Ods_Populated_Template_log.ldf';"
Expand Down
2 changes: 1 addition & 1 deletion Docker/ods-api-web-api/alpine/mssql/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ do
STATUS_ODS=1
until [[ $STATUS_ODS -eq 0 ]]; do
>&2 echo "SQL Server '$HOST' is unavailable - sleeping"
STATUS_ODS=$(/opt/mssql-tools18/bin/sqlcmd -W -h -1 -U ${SQLSERVER_USER} -P "${SQLSERVER_PASSWORD}" -S ${HOST} -C -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" 2> /dev/null || echo 1)
STATUS_ODS=$(/opt/mssql-tools18/bin/sqlcmd -C -W -h -1 -U ${SQLSERVER_USER} -P "${SQLSERVER_PASSWORD}" -S ${HOST} -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" 2> /dev/null || echo 1)

sleep 10
done
Expand Down
4 changes: 2 additions & 2 deletions Docker/ods-api-web-sandbox-admin/alpine/mssql/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ STATUS_ODS=1
STATUS_ADMIN=1
until [[ $STATUS_ODS -eq 0 && $STATUS_ADMIN -eq 0 ]]; do
>&2 echo "ODS SQL Server is unavailable - sleeping"
STATUS_ODS=$(/opt/mssql-tools18/bin/sqlcmd -W -h -1 -U ${SQLSERVER_USER} -P "${SQLSERVER_PASSWORD}" -S ${SQLSERVER_ODS_DATASOURCE} -C -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" 2> /dev/null || echo 1)
STATUS_ODS=$(/opt/mssql-tools18/bin/sqlcmd -C -W -h -1 -U ${SQLSERVER_USER} -P "${SQLSERVER_PASSWORD}" -S ${SQLSERVER_ODS_DATASOURCE} -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" 2> /dev/null || echo 1)

>&2 echo "ADMIN SQL Server is unavailable - sleeping"
STATUS_ADMIN=$(/opt/mssql-tools18/bin/sqlcmd -W -h -1 -U ${SQLSERVER_USER} -P "${SQLSERVER_PASSWORD}" -S ${SQLSERVER_ADMIN_DATASOURCE} -C -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" 2> /dev/null || echo 1)
STATUS_ADMIN=$(/opt/mssql-tools18/bin/sqlcmd -C -W -h -1 -U ${SQLSERVER_USER} -P "${SQLSERVER_PASSWORD}" -S ${SQLSERVER_ADMIN_DATASOURCE} -Q "SET NOCOUNT ON; SELECT SUM(state) FROM sys.databases" 2> /dev/null || echo 1)

sleep 10
done
Expand Down

0 comments on commit 9f00274

Please sign in to comment.