Skip to content

Commit

Permalink
adding shanes goodies
Browse files Browse the repository at this point in the history
  • Loading branch information
jpomfret committed Apr 12, 2023
1 parent 4c3a589 commit 68246fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
9 changes: 9 additions & 0 deletions source/checks/Databasev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,12 @@ Describe "Query Store Disabled" -Tag QueryStoreDisabled, Medium, Database -ForEa
}
}

Describe "Compatibility Level" -Tag CompatibilityLevel, High, Database -ForEach $InstancesToTest {
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.database.compatibilitylevel').Value

Context "Compatibility level matches server compatibility level" {
It "Database <_.Name> has the expected compatibility level on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.compatexclude -notcontains $psitem.Name } } {
$psitem.CompatibilityLevel | Should -Be $psitem.ServerLevel -Because "it means you are on the appropriate compatibility level for your SQL Server version to use all available features."
}
}
}
3 changes: 3 additions & 0 deletions source/internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ Set-PSFConfig -Module dbachecks -Name policy.database.status.excludeoffline -Val
Set-PSFConfig -Module dbachecks -Name policy.database.status.excluderestoring -Value @() -Initialize -Description "Database names that we expect to be restoring"
Set-PSFConfig -Module dbachecks -Name database.querystoreenabled.excludedb -Value @('model', 'tempdb', 'master') -Initialize -Description "A List of databases that we do not want to check for Query Store enabled"
Set-PSFConfig -Module dbachecks -Name database.querystoredisabled.excludedb -Value @('model', 'tempdb', 'master') -Initialize -Description "A List of databases that we do not want to check for Query Store disabled"
Set-PSFConfig -Module dbachecks -Name database.compatibilitylevel.excludedb -Value @() -Initialize -Description "A list of databases that we do not want to check compatibility level"

Set-PSFConfig -Module dbachecks -Name policy.database.filegrowthdaystocheck -Value $null -Initialize -Description "The number of days to go back to check for growth events"
Set-PSFConfig -Module dbachecks -Name policy.database.trustworthyexcludedb -Value @('msdb') -Initialize -Description "A List of databases that we do not want to check for Trustworthy being on"
Set-PSFConfig -Module dbachecks -Name policy.database.duplicateindexexcludedb -Value @('msdb', 'ReportServer', 'ReportServerTempDB') -Initialize -Description "A List of databases we do not want to check for Duplicate Indexes"
Expand Down Expand Up @@ -319,6 +321,7 @@ Set-PSFConfig -Module dbachecks -Name skip.database.autoupdatestatistics -Valida
Set-PSFConfig -Module dbachecks -Name skip.database.autoupdatestatisticsasynchronously -Validation bool -Value $false -Initialize -Description "Skip the auto update statistics asynchronously test"
Set-PSFConfig -Module dbachecks -Name skip.database.trustworthy -Validation bool -Value $false -Initialize -Description "Skip the trustworthy database test"
Set-PSFConfig -Module dbachecks -Name skip.database.status -Validation bool -Value $false -Initialize -Description "Skip the database status test"
Set-PSFConfig -Module dbachecks -Name skip.database.compatibilitylevel -Validation bool -Value $false -Initialize -Description "Skip the database compatibility test"


Set-PSFConfig -Module dbachecks -Name skip.logshiptesting -Validation bool -Value $false -Initialize -Description "Skip the logshipping test"
Expand Down
10 changes: 7 additions & 3 deletions source/internal/functions/Get-AllDatabaseInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ function Get-AllDatabaseInfo {
$qs = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'qsdisabledexclude' -Value (Get-DbcConfigValue database.querystoredisabled.excludedb)
}

'CompatibilityLevel' {
$compatibilityLevel = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'compatexclude' -Value (Get-DbcConfigValue database.compatibilitylevel.excludedb)
}
Default { }
}

Expand Down Expand Up @@ -164,9 +167,10 @@ function Get-AllDatabaseInfo {
IsDatabaseSnapshot = @(if ($status) { $psitem.IsDatabaseSnapshot }) # needed for status test
Readonly = @(if ($status) { $psitem.Readonly }) # needed for status test
QueryStore = @(if ($qs) { $psitem.QueryStoreOptions.ActualState })

CompatibilityLevel = @(if ($compatibilitylevel) { $psitem.CompatibilityLevel })
ServerLevel = @(if ($compatibilitylevel) { [Enum]::GetNames('Microsoft.SqlServer.Management.Smo.CompatibilityLevel').Where{ $psitem -match $Instance.VersionMajor } })
}
}
}
return $testInstanceObject
}
}

0 comments on commit 68246fd

Please sign in to comment.