Skip to content

Commit

Permalink
SqlSetup: Support SQL Server Major Version Upgrade (#1562)
Browse files Browse the repository at this point in the history
- SqlSetup
  - Added support for major version upgrade (issue #1561).
  • Loading branch information
Carv01 committed Jun 10, 2020
1 parent 3a449f5 commit 31e059b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -36,6 +36,8 @@ in a future release.

### Added

- SqlSetup
- Added support for major version upgrade ([issue #1561](https://github.com/dsccommunity/SqlServerDsc/issues/1561)).
- SqlServerDsc
- Added new resource SqlServerProtocol ([issue #1377](https://github.com/dsccommunity/SqlServerDsc/issues/1377)).
- Added new resource SqlServerProtocolTcpIp ([issue #1378](https://github.com/dsccommunity/SqlServerDsc/issues/1378)).
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -1899,6 +1899,7 @@ Installs SQL Server on the target node.
* SqlTempdbFileGrowth
* SqlTempdbLogFileSize
* SqlTempdbLogFileGrowth
* Major version upgrades are supported if the action "upgrade" is specified.

> **Note:** It is not possible to add or remove features to a SQL Server failover
cluster. This is a limitation of SQL Server. See article
Expand Down
15 changes: 15 additions & 0 deletions source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1
Expand Up @@ -2190,6 +2190,21 @@ function Test-TargetResource
}
}

if ($getTargetResourceParameters.Action -eq 'Upgrade')
{
$installerSqlVersion = Get-SqlMajorVersion -Path (Join-Path -Path $sourcePath -ChildPath 'setup.exe')
$instanceSqlVersion = Get-SQLInstanceMajorVersion -InstanceName $InstanceName

if ($installerSQLVersion -gt $instanceSqlVersion)
{
Write-Verbose -Message (
$script:localizedData.DifferentMajorVersion -f $InstanceName, $instanceSqlVersion, $installerSqlVersion
)

$result = $false
}
}

return $result
}

Expand Down
Expand Up @@ -63,4 +63,5 @@ ConvertFrom-StringData @'
MasterDataServicesFeatureNotFound = Master Data Services (MDS) feature not detected.
FeatureAlreadyInstalled = The feature '{0}' is already installed so it will not be installed again.
FeatureFlag = Using feature flag '{0}'
DifferentMajorVersion = The instance '{0}' has the wrong major version. The major version is '{1}', but expected version '{2}'.
'@
Expand Up @@ -63,4 +63,5 @@ ConvertFrom-StringData @'
MasterDataServicesFeatureNotFound = Master Data Services (MDS) funktionen hittades inte.
FeatureAlreadyInstalled = Funktionen '{0}' är redan installerad så den kommer inte bli installerad igen.
FeatureFlag = Använder tilläggsflagga '{0}'
DifferentMajorVersion = The instance '{0}' has the wrong major version. The major version is '{1}', but expected version '{2}'.
'@
35 changes: 35 additions & 0 deletions tests/Unit/DSC_SqlSetup.Tests.ps1
Expand Up @@ -1490,6 +1490,8 @@ try

Describe 'SqlSetup\Test-TargetResource' -Tag 'Test' {
BeforeAll {
$mockSourcePath = $TestDrive.FullName

<#
These are written with both lower-case and upper-case to make sure we support that.
The feature list must be written in the order it is returned by the function Get-TargetResource.
Expand Down Expand Up @@ -1591,6 +1593,39 @@ try
Assert-MockCalled -CommandName Get-TargetResource -Exactly -Times 1 -Scope 'It'
}
}

Context 'When Action is set to ''Upgrade'' and current major version is not the expected' {
BeforeAll {
$testParameters = $mockDefaultParameters.Clone()
$testParameters += @{
Action = 'Upgrade'
InstanceName = $mockDefaultInstance_InstanceName
SourceCredential = $null
SourcePath = $mockSourcePath
}

Mock -CommandName Get-TargetResource -MockWith {
return @{
Features = $mockDefaultFeatures
}
}

Mock -CommandName Get-SqlMajorVersion -MockWith {
return '15'
}

Mock -CommandName Get-SQLInstanceMajorVersion -MockWith {
return '14'
}
}

It 'Should return $false' {
$result = Test-TargetResource @testParameters -Verbose
$result | Should -BeFalse

Assert-MockCalled -CommandName Get-TargetResource -Exactly -Times 1 -Scope 'It'
}
}
}

Context "When the system is in the desired state" {
Expand Down

0 comments on commit 31e059b

Please sign in to comment.