From 198598bc58a8b64bbaca566ed31613bb9b0aec80 Mon Sep 17 00:00:00 2001 From: Mladen Celikovic Date: Fri, 7 Feb 2020 21:12:27 -0500 Subject: [PATCH 1/2] Fixed the issue with DropTruncateIfExists - syntax error with previous inline comment --- .../6_DeployScriptsToSqldw/RunDSQLScriptsDriver.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/APS to SQL DW Migration - Schema and Data Migration with PolyBase/6_DeployScriptsToSqldw/RunDSQLScriptsDriver.ps1 b/APS to SQL DW Migration - Schema and Data Migration with PolyBase/6_DeployScriptsToSqldw/RunDSQLScriptsDriver.ps1 index 608c5dd..9632b9b 100644 --- a/APS to SQL DW Migration - Schema and Data Migration with PolyBase/6_DeployScriptsToSqldw/RunDSQLScriptsDriver.ps1 +++ b/APS to SQL DW Migration - Schema and Data Migration with PolyBase/6_DeployScriptsToSqldw/RunDSQLScriptsDriver.ps1 @@ -230,7 +230,8 @@ ForEach ($S in $csvFile ) $ReturnValues = RunSQLScriptFile -ServerName $ServerName -Username $UserName -Password $Password -SQLDWADIntegrated $ConnectToSQLDW -Database $DatabaseName -Query $Query } - else#if($DropTruncateIfExists -eq '' -or [string]::IsNullOrEmpty($DropTruncateIfExists)) + #elseif($DropTruncateIfExists -eq '' -or [string]::IsNullOrEmpty($DropTruncateIfExists)) + else { $RunStatement = 0 } From dd1f86d2be14348f025b3a346209365f73af8ab1 Mon Sep 17 00:00:00 2001 From: Mladen Celikovic Date: Fri, 7 Feb 2020 21:49:27 -0500 Subject: [PATCH 2/2] Check if schema exists, prevent failure of schema creation in case of multiple rows flagged and both, object and schema will be created for a csv row. --- .../6_DeployScriptsToSqldw/RunDSQLScriptsDriver.ps1 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/APS to SQL DW Migration - Schema and Data Migration with PolyBase/6_DeployScriptsToSqldw/RunDSQLScriptsDriver.ps1 b/APS to SQL DW Migration - Schema and Data Migration with PolyBase/6_DeployScriptsToSqldw/RunDSQLScriptsDriver.ps1 index 9632b9b..2ebbd3f 100644 --- a/APS to SQL DW Migration - Schema and Data Migration with PolyBase/6_DeployScriptsToSqldw/RunDSQLScriptsDriver.ps1 +++ b/APS to SQL DW Migration - Schema and Data Migration with PolyBase/6_DeployScriptsToSqldw/RunDSQLScriptsDriver.ps1 @@ -104,12 +104,16 @@ Function GetSchemaStatement [Parameter(Position=1, Mandatory=$false)] [string]$SchemaAuth ) - $Query = "CREATE SCHEMA $SchemaName" + $Query = "IF NOT EXISTS(SELECT * FROM [INFORMATION_SCHEMA].[SCHEMATA] WHERE [SCHEMA_NAME] = '" + $SchemaName + "') + BEGIN + EXEC('CREATE SCHEMA " + $SchemaName If($SchemaAuth -ne "") { - $Query = $Query + ' AUTHORIZATION [' + $SchemaAuth + ']' + $Query = $Query + " AUTHORIZATION [" + $SchemaAuth + "]" } + + $Query = $Query + "') END" return $Query @@ -244,7 +248,12 @@ ForEach ($S in $csvFile ) #$Query = [System.IO.File]::ReadAllText("$ScriptToRun") $Query = GetSchemaStatement -SchemaName $SchemaName -SchemaAuth $SchemaAuth + #Create schema: $ReturnValues = RunSQLScriptFile -ServerName $ServerName -Username $UserName -Password $Password -SQLDWADIntegrated $ConnectToSQLDW -Database $DatabaseName -Query $Query -Variables $Variables #-SchemaName $SchemaName -TableName $TableName -DropIfExists $DropIfExists -StatusLogFile $StatusLogFile + + #Create object: + $ReturnValues = RunSQLScriptFile -ServerName $ServerName -Username $UserName -Password $Password -SQLDWADIntegrated $ConnectToSQLDW -Database $DatabaseName -InputFile $ScriptToRun -Variables $Variables #-SchemaName $SchemaName -TableName $TableName -DropIfExists $DropIfExists -StatusLogFile $StatusLogFile + } else {