Commit c6e995a1 authored by CarpathiaLaptop's avatar CarpathiaLaptop
Browse files

fixing various bugs around filegroups.

changing RunMD3.ps1 so one master .sql file is created for every deployment
parent ef7d047a
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -11,10 +11,10 @@ BEGIN
			IncludedColumns		VARCHAR(MAX) NULL,
			IncludedColumns		VARCHAR(MAX) NULL,
			IsClustered			BIT NOT NULL,
			IsClustered			BIT NOT NULL,
			IsUnique			BIT NOT NULL,
			IsUnique			BIT NOT NULL,
			FGorPartitionScheme	VARCHAR(MAX)NOT NULL,
			FGorPartitionScheme	VARCHAR(MAX) NULL,
			IdxFillFactor		INT NOT NULL,
			IdxFillFactor		INT NOT NULL,
			IsPadded			BIT NOT NULL,
			IsPadded			BIT NOT NULL,
			CompressionSetting	VARCHAR(256) NOT NULL,
			CompressionSetting	VARCHAR(256) NULL,
			DropIndex			BIT NOT NULL
			DropIndex			BIT NOT NULL


	);
	);
+3 −3
Original line number Original line Diff line number Diff line
@@ -11,8 +11,8 @@ BEGIN
    IsClustered	BIT NOT NULL,  
    IsClustered	BIT NOT NULL,  
	IdxFillFactor int NOT NULL,
	IdxFillFactor int NOT NULL,
	IsPadded BIT NOT NULL,
	IsPadded BIT NOT NULL,
    FGorPartitionScheme VARCHAR(MAX) NOT NULL,
    FGorPartitionScheme VARCHAR(MAX) NULL,
	CompressionSetting varchar(255) NOT NULL,
	CompressionSetting varchar(255) NULL,
	DropPK BIT NOT NULL
	DropPK BIT NOT NULL
	);
	);
	   
	   
@@ -20,4 +20,4 @@ BEGIN
	PRIMARY KEY CLUSTERED (Id);
	PRIMARY KEY CLUSTERED (Id);
		
		
END 
END 
--drop table MD3.PrimaryKeys
+1 −1
Original line number Original line Diff line number Diff line
@@ -67,7 +67,7 @@ BEGIN
		SELECT @SchemaName = MD3.f_RemoveBrackets (@SchemaName);
		SELECT @SchemaName = MD3.f_RemoveBrackets (@SchemaName);
		SELECT @TableName = MD3.f_RemoveBrackets (@TableName);
		SELECT @TableName = MD3.f_RemoveBrackets (@TableName);
		SELECT @IndexName = MD3.f_RemoveBrackets (@IndexName);
		SELECT @IndexName = MD3.f_RemoveBrackets (@IndexName);
		SELECT @FileGroupOrPartition = MD3.f_RemoveBrackets (@FileGroupOrPartition);
		SELECT @FileGroupOrPartition = MD3.f_RemoveBrackets (ISNULL(@FileGroupOrPartition,'PRIMARY'));
		SELECT @IndexKeyColumns = MD3.f_RemoveBrackets (@IndexKeyColumns);
		SELECT @IndexKeyColumns = MD3.f_RemoveBrackets (@IndexKeyColumns);
		SELECT @IndexKeyColumns = REPLACE(@IndexKeyColumns,' ','')
		SELECT @IndexKeyColumns = REPLACE(@IndexKeyColumns,' ','')
		SELECT @IncludedColumns = MD3.f_RemoveBrackets (@IncludedColumns);
		SELECT @IncludedColumns = MD3.f_RemoveBrackets (@IncludedColumns);
+1 −1
Original line number Original line Diff line number Diff line
@@ -39,7 +39,7 @@ BEGIN
		SELECT @SchemaName = MD3.f_RemoveBrackets (@SchemaName);
		SELECT @SchemaName = MD3.f_RemoveBrackets (@SchemaName);
		SELECT @TableName = MD3.f_RemoveBrackets (@TableName);
		SELECT @TableName = MD3.f_RemoveBrackets (@TableName);
		SELECT @PrimaryKeyName = MD3.f_RemoveBrackets (@PrimaryKeyName);
		SELECT @PrimaryKeyName = MD3.f_RemoveBrackets (@PrimaryKeyName);
		SELECT @FileGroupOrPartition = MD3.f_RemoveBrackets (@FileGroupOrPartition);
		SELECT @FileGroupOrPartition = MD3.f_RemoveBrackets (ISNULL(@FileGroupOrPartition,'PRIMARY'));
		SELECT @KeyColumns = MD3.f_RemoveBrackets (@KeyColumns);
		SELECT @KeyColumns = MD3.f_RemoveBrackets (@KeyColumns);
		--Set the compression option
		--Set the compression option
		SELECT @DataCompressionType = COALESCE(@DataCompressionType, 'NONE') ;
		SELECT @DataCompressionType = COALESCE(@DataCompressionType, 'NONE') ;
+14 −8
Original line number Original line Diff line number Diff line
param (
param (
	[Parameter(Position=0, Mandatory=$true)] [string]$ServerName,   #(local), SomeServer, SomeServer\InstanceName
	[Parameter(Position=0, Mandatory=$true)] [string]$ServerName,   #(local), SomeServer, SomeServer\InstanceName
	[Parameter(Position=1, Mandatory=$true)] [string]$DatabaseName
	[Parameter(Position=1, Mandatory=$true)] [string]$DatabaseName,
	[Parameter(Position=2, Mandatory=$false)] [bool]$ScriptOnly  #do not apply to db, only generate the script
)
)
################################################################################
################################################################################
#  RunMD3.ps1
#  RunMD3.ps1
@@ -33,6 +34,8 @@ $script:ErrorActionPreference = "Stop"


$workingDirectory = (Split-Path $MyInvocation.MyCommand.Path)
$workingDirectory = (Split-Path $MyInvocation.MyCommand.Path)
$CurrentSQLScriptDirectory = $workingDirectory
$CurrentSQLScriptDirectory = $workingDirectory
$ScriptFile = "DeploymentScript.sql"
$ScriptFilePath = (Join-Path $workingDirectory $ScriptFile)


################################################################################
################################################################################
#     Helper Functions
#     Helper Functions
@@ -153,12 +156,8 @@ function Recurse-Folders {
	#check for Open transactions
	#check for Open transactions
	$MergedOutput += "IF OBJECT_ID('MD3.OpenTransactionsCheck') IS NOT NULL EXEC MD3.OpenTransactionsCheck"
	$MergedOutput += "IF OBJECT_ID('MD3.OpenTransactionsCheck') IS NOT NULL EXEC MD3.OpenTransactionsCheck"
	
	
	# Run the script on the server
	# Append this code to existing ScriptFile
	$MergedOutput | Out-File -Encoding "Unicode" -FilePath (Join-Path $folderspec "_tempMD3.tmp")  -Force  
	$MergedOutput | Out-File -Encoding "Unicode" -FilePath $ScriptFilePath -Append
	RunSqlCmdForFile (Join-Path $folderspec "_tempMD3.tmp")
	Remove-Item (Join-Path $folderspec "_tempMD3.tmp")
		
	
	
	
	# now, starting with folderspec, traverse the directory tree , skip all folders that start with _ (underscore)
	# now, starting with folderspec, traverse the directory tree , skip all folders that start with _ (underscore)
	foreach ($subfolder in (Get-ChildItem $folderspec | Where-Object {$_.PSIsContainer -and $_.Name -notlike "_*"}) | Sort-Object Name){
	foreach ($subfolder in (Get-ChildItem $folderspec | Where-Object {$_.PSIsContainer -and $_.Name -notlike "_*"}) | Sort-Object Name){
@@ -180,11 +179,18 @@ Try
	# Run the "master only" script 
	# Run the "master only" script 
	RunCreateDbScript
	RunCreateDbScript
	
	
	# Prepare the ScriptFile
	"`n" | Out-File -Encoding "Unicode" -FilePath $ScriptFilePath -Force  
	
	
	InsertMD3LogMessage -Message "Starting MD3 deployment" -Severity "I" -ScriptName "RunMD3.ps1"
	InsertMD3LogMessage -Message "Starting MD3 deployment" -Severity "I" -ScriptName "RunMD3.ps1"
	
	
	# Run all .sql files, then subfolders, alphabetically
	# Merge all .sql files, then subfolders, alphabetically
	Recurse-Folders $CurrentSQLScriptDirectory
	Recurse-Folders $CurrentSQLScriptDirectory
	
	
	# Now run all files
	RunSqlCmdForFile $ScriptFilePath
	
	InsertMD3LogMessage -Message "Completed MD3 deployment" -Severity "I" -ScriptName "RunMD3.ps1"
	InsertMD3LogMessage -Message "Completed MD3 deployment" -Severity "I" -ScriptName "RunMD3.ps1"
	Write-Host "MD3 has completed with success.  WARNINGs are displayed above."
	Write-Host "MD3 has completed with success.  WARNINGs are displayed above."