diff --git a/CHANGELOG.md b/CHANGELOG.md index 11a8f301c..d2cc72d16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)). diff --git a/README.md b/README.md index 9e4dacf25..60433eefd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 b/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 index 916d9c236..f65a441e3 100644 --- a/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 +++ b/source/DSCResources/DSC_SqlSetup/DSC_SqlSetup.psm1 @@ -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 } diff --git a/source/DSCResources/DSC_SqlSetup/en-US/DSC_SqlSetup.strings.psd1 b/source/DSCResources/DSC_SqlSetup/en-US/DSC_SqlSetup.strings.psd1 index 8a0383e51..698af2127 100644 --- a/source/DSCResources/DSC_SqlSetup/en-US/DSC_SqlSetup.strings.psd1 +++ b/source/DSCResources/DSC_SqlSetup/en-US/DSC_SqlSetup.strings.psd1 @@ -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}'. '@ diff --git a/source/DSCResources/DSC_SqlSetup/sv-SE/DSC_SqlSetup.strings.psd1 b/source/DSCResources/DSC_SqlSetup/sv-SE/DSC_SqlSetup.strings.psd1 index 95d5d65c2..d616f9e79 100644 --- a/source/DSCResources/DSC_SqlSetup/sv-SE/DSC_SqlSetup.strings.psd1 +++ b/source/DSCResources/DSC_SqlSetup/sv-SE/DSC_SqlSetup.strings.psd1 @@ -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}'. '@ diff --git a/tests/Unit/DSC_SqlSetup.Tests.ps1 b/tests/Unit/DSC_SqlSetup.Tests.ps1 index 939b19fbd..eab88e903 100644 --- a/tests/Unit/DSC_SqlSetup.Tests.ps1 +++ b/tests/Unit/DSC_SqlSetup.Tests.ps1 @@ -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. @@ -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" {