-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SqlSetup: Add better validation of features (#1911)
- New public command: - `Test-SqlDscIsSupportedFeature` - Evaluates if a feature is supported by a specific Microsoft SQL Server major version. _This command must be extended with_ _a full list of when features were added and removed in each major_ _version to fully work_. - New private commands: - `Get-FileVersionInformation` - Returns the version information for a file. - `Assert-Feature` - Throws an exception if a feature is not supported for a specific Microsoft SQL Server major version. - Update private command: - `Assert-SetupActionProperties` was changed to throw an exception when a feature is not supported (uses `Assert-Feature`). The private function indirectly used by the setup action commands. - SqlSetup - Update to support checking non-supported features using the command `SqlDscIsSupportedFeature` ([issue #1872).
- Loading branch information
Showing
13 changed files
with
731 additions
and
13 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
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
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
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,54 @@ | ||
<# | ||
.SYNOPSIS | ||
Assert that a feature is supported by a Microsoft SQL Server major version. | ||
.DESCRIPTION | ||
Assert that a feature is supported by a Microsoft SQL Server major version. | ||
.PARAMETER Feature | ||
Specifies the feature to evaluate. | ||
.PARAMETER ProductVersion | ||
Specifies the product version of the Microsoft SQL Server. At minimum the | ||
major version must be provided. | ||
.EXAMPLE | ||
Assert-Feature -Feature 'RS' -ProductVersion '14' | ||
Throws an exception if the feature is not supported. | ||
.OUTPUTS | ||
None. | ||
#> | ||
function Assert-Feature | ||
{ | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
[System.String[]] | ||
$Feature, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$ProductVersion | ||
) | ||
|
||
process | ||
{ | ||
foreach ($currentFeature in $Feature) | ||
{ | ||
if (-not ($currentFeature | Test-SqlDscIsSupportedFeature -ProductVersion $ProductVersion)) | ||
{ | ||
$PSCmdlet.ThrowTerminatingError( | ||
[System.Management.Automation.ErrorRecord]::new( | ||
($script:localizedData.Feature_Assert_NotSupportedFeature -f $currentFeature, $ProductVersion), | ||
'AF0001', # cSpell: disable-line | ||
[System.Management.Automation.ErrorCategory]::InvalidOperation, | ||
$currentFeature | ||
) | ||
) | ||
} | ||
} | ||
} | ||
} |
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
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,53 @@ | ||
<# | ||
.SYNOPSIS | ||
Returns the version information for a file. | ||
.DESCRIPTION | ||
Returns the version information for a file. | ||
.PARAMETER FilePath | ||
Specifies the file for which to return the version information. | ||
.EXAMPLE | ||
Get-FileVersionInformation -FilePath 'E:\setup.exe' | ||
Returns the version information for the file setup.exe. | ||
.EXAMPLE | ||
Get-FileVersionInformation -FilePath (Get-Item -Path 'E:\setup.exe') | ||
Returns the version information for the file setup.exe. | ||
.OUTPUTS | ||
[System.String] | ||
#> | ||
function Get-FileVersionInformation | ||
{ | ||
[OutputType([System.Diagnostics.FileVersionInfo])] | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
[System.IO.FileInfo] | ||
$FilePath | ||
) | ||
|
||
process | ||
{ | ||
$file = Get-Item -Path $FilePath -ErrorAction 'Stop' | ||
|
||
if ($file.PSIsContainer) | ||
{ | ||
$PSCmdlet.ThrowTerminatingError( | ||
[System.Management.Automation.ErrorRecord]::new( | ||
$script:localizedData.FileVersionInformation_Get_FilePathIsNotFile, | ||
'GFPVI0001', # cSpell: disable-line | ||
[System.Management.Automation.ErrorCategory]::InvalidArgument, | ||
$file.FullName | ||
) | ||
) | ||
} | ||
|
||
return $file.VersionInfo | ||
} | ||
} |
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,99 @@ | ||
<# | ||
.SYNOPSIS | ||
Tests that a feature is supported by a Microsoft SQL Server major version. | ||
.DESCRIPTION | ||
Tests that a feature is supported by a Microsoft SQL Server major version. | ||
.PARAMETER Feature | ||
Specifies the feature to evaluate. | ||
.PARAMETER ProductVersion | ||
Specifies the product version of the Microsoft SQL Server. At minimum the | ||
major version must be provided. | ||
.EXAMPLE | ||
Test-SqlDscIsSupportedFeature -Feature 'RS' -ProductVersion '13' | ||
Returns $true if the feature is supported. | ||
.OUTPUTS | ||
[System.Boolean] | ||
#> | ||
function Test-SqlDscIsSupportedFeature | ||
{ | ||
[OutputType([System.Boolean])] | ||
[CmdletBinding()] | ||
param | ||
( | ||
[Parameter(Mandatory = $true, ValueFromPipeline = $true)] | ||
[System.String] | ||
$Feature, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[System.String] | ||
$ProductVersion | ||
) | ||
|
||
begin | ||
{ | ||
$targetMajorVersion = ($ProductVersion -split '\.')[0] | ||
|
||
<# | ||
List of features that was removed from a specific major version (and later). | ||
Feature list: https://learn.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-from-the-command-prompt#Feature | ||
#> | ||
$removedFeaturesPerMajorVersion = @{ | ||
13 = @('ADV_SSMS', 'SSMS') # cSpell: disable-line | ||
14 = @('RS', 'RS_SHP', 'RS_SHPWFE') # cSpell: disable-line | ||
16 = @('Tools', 'BC', 'CONN', 'BC', 'DREPLAY_CTLR', 'DREPLAY_CLT', 'SNAC_SDK', 'SDK', 'PolyBaseJava', 'SQL_INST_MR', 'SQL_INST_MPY', 'SQL_SHARED_MPY', 'SQL_SHARED_MR') # cSpell: disable-line | ||
} | ||
|
||
<# | ||
List of features that was added to a specific major version. | ||
Feature list: https://learn.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-from-the-command-prompt#Feature | ||
#> | ||
$addedFeaturesPerMajorVersion = @{ | ||
13 = @('SQL_INST_MR', 'SQL_INST_MPY', 'SQL_INST_JAVA') | ||
15 = @('PolyBaseCore', 'PolyBaseJava', 'SQL_INST_JAVA') # cSpell: disable-line | ||
} | ||
|
||
# Evaluate features that was removed and are unsupported for the target's major version. | ||
$targetUnsupportedFeatures = $removedFeaturesPerMajorVersion.Keys | | ||
Where-Object -FilterScript { | ||
$_ -le $targetMajorVersion | ||
} | | ||
ForEach-Object -Process { | ||
$removedFeaturesPerMajorVersion.$_ | ||
} | ||
|
||
<# | ||
Evaluate features that was added to higher major versions than the | ||
target's major version which will be unsupported for the target's | ||
major version. | ||
#> | ||
$targetUnsupportedFeatures += $addedFeaturesPerMajorVersion.Keys | | ||
Where-Object -FilterScript { | ||
$_ -gt $targetMajorVersion | ||
} | | ||
ForEach-Object -Process { | ||
$addedFeaturesPerMajorVersion.$_ | ||
} | ||
|
||
$supported = $true | ||
} | ||
|
||
process | ||
{ | ||
# This does case-insensitive match against the list of unsupported features. | ||
if ($targetUnsupportedFeatures -and $Feature -in $targetUnsupportedFeatures) | ||
{ | ||
$supported = $false | ||
} | ||
} | ||
|
||
end | ||
{ | ||
return $supported | ||
} | ||
} |
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
Oops, something went wrong.