-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Drop schemas * Add mixin * Lint and checks * Lint fixes * Lint fixes
- Loading branch information
Showing
6 changed files
with
94 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
templates/workspace_services/ohdsi/scripts/synapse_runner.sh
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
templates/workspace_services/ohdsi/sql/drop_synapse_schemas.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/****** Copy Data ******/ | ||
CREATE TABLE #tbl | ||
WITH | ||
( DISTRIBUTION = ROUND_ROBIN | ||
) | ||
AS | ||
SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS Sequence | ||
, [name] | ||
, 'DROP TABLE ' + N'$(RESULTS_SCHEMA_NAME)' + '.' + name AS sql_code | ||
FROM sys.tables | ||
WHERE schema_id = (select schema_id from sys.schemas where name = N'$(RESULTS_SCHEMA_NAME)') | ||
; | ||
|
||
DECLARE @nbr_statements INT = (SELECT COUNT(*) FROM #tbl) | ||
, @i INT = 1 | ||
; | ||
|
||
WHILE @i <= @nbr_statements | ||
BEGIN | ||
DECLARE @sql_code NVARCHAR(4000) = (SELECT sql_code FROM #tbl WHERE Sequence = @i); | ||
EXEC sp_executesql @sql_code; | ||
SET @i +=1; | ||
END | ||
|
||
DROP TABLE #tbl; | ||
|
||
/****** Drop Schemas ******/ | ||
|
||
DROP SCHEMA [$(RESULTS_SCHEMA_NAME)]; | ||
DROP SCHEMA [$(TEMP_SCHEMA_NAME)]; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
if [[ -z ${DATA_SOURCE_CONFIG:-} ]] || [[ -z ${DATA_SOURCE_DIAMONS:-} ]]; then | ||
printf 'No data source or daimons configured.' | ||
exit 0 | ||
else | ||
# Parse Data source | ||
ds_config="$(echo "$DATA_SOURCE_CONFIG" | base64 --decode)" | ||
ds_daimons="$(echo "$DATA_SOURCE_DIAMONS" | base64 --decode)" | ||
dialect="$(jq -r '.dialect' <<< "$ds_config")" | ||
|
||
if [[ $dialect != "Azure Synapse" ]]; then | ||
printf 'Not a Synapse data source, no action required.' | ||
exit 0 | ||
fi | ||
|
||
origin_results_schema_name="$(jq -r '.daimon_results' <<< "$ds_daimons")" | ||
origin_temp_schema_name="$(jq -r '.daimon_temp' <<< "$ds_daimons")" | ||
if [[ -z $origin_results_schema_name ]] || [[ -z $origin_temp_schema_name ]]; then | ||
printf 'Results and temp schemas are not configured.' | ||
exit 0 | ||
fi | ||
|
||
# Parse required info | ||
admin_user="$(jq -r '.username' <<< "$ds_config")" | ||
jdbc_connection_string="$(jq -r '.connection_string' <<< "$ds_config")" | ||
synapse_server="$([[ $jdbc_connection_string =~ jdbc:sqlserver://(.*):1433 ]] && echo "${BASH_REMATCH[1]}")" | ||
synapse_db="$([[ $jdbc_connection_string =~ database=(.*)(;user) ]] && echo "${BASH_REMATCH[1]}")" | ||
origin_results_schema_name="$(jq -r '.daimon_results' <<< "$ds_daimons")" | ||
origin_temp_schema_name="$(jq -r '.daimon_temp' <<< "$ds_daimons")" | ||
parsed_resource_id="$(echo "$TRE_RESOURCE_ID" | tr - _ )" | ||
results_schema_name="${origin_results_schema_name}_${parsed_resource_id}" | ||
temp_schema_name="${origin_temp_schema_name}_${parsed_resource_id}" | ||
|
||
# Export password as required by sqlcmd tool | ||
# shellcheck disable=SC2155 | ||
export SQLCMDPASSWORD="$(jq -r '.password' <<< "$ds_config")" | ||
|
||
printf 'Execute Synapse SQL script' | ||
sqlcmd -U "${admin_user}" -S "${synapse_server}" -d "${synapse_db}" -W -v RESULTS_SCHEMA_NAME="${results_schema_name}" -v TEMP_SCHEMA_NAME="${temp_schema_name}" -v ORIGIN_RESULTS_SCHEMA_NAME="${origin_results_schema_name}" -i "${SCRIPT_PATH}" | ||
printf 'Execute Synapse SQL script: done.' | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters