Skip to content

Commit c9ced52

Browse files
committed
autoclose - #884
1 parent 57cd8dd commit c9ced52

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

checks/Databasev5.Tests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,13 @@ Describe "Auto Close" -Tag AutoClose, High, Database -ForEach $InstancesToTest {
110110
$psitem.AutoClose | Should -Be $psitem.ConfigValues.autoclose -Because "Because!"
111111
}
112112
}
113+
}
114+
115+
Describe "Auto Shrink" -Tag AutoShrink, High, Database -ForEach $InstancesToTest {
116+
$skip = Get-DbcConfigValue skip.database.autoshrink
117+
Context "Testing Auto Shrink on <_.Name>" {
118+
It "Database <_.Name> should have Auto Shrink set to <_.ConfigValues.autoshrink> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.autoshrinkexclude -notcontains $PsItem.Name } } {
119+
$psitem.AutoShrink | Should -Be $psitem.ConfigValues.autoshrink -Because "Shrinking databases causes fragmentation and performance issues"
120+
}
121+
}
113122
}

internal/configurations/configuration.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ Set-PSFConfig -Module dbachecks -Name policy.build.behind -Value $null -Initiali
231231
# exclude databases
232232
Set-PSFConfig -Module dbachecks -Name policy.asymmetrickeysize.excludedb -Value @('master', 'msdb', 'tempdb') -Initialize -Description "Databases to exclude from asymmetric key size checks"
233233
Set-PSFConfig -Module dbachecks -Name policy.autoclose.excludedb -Value @() -Initialize -Description "Databases to exclude from autoclose key size checks"
234+
Set-PSFConfig -Module dbachecks -Name policy.autoshrink.excludedb -Value @() -Initialize -Description "Databases to exclude from autoclose key size checks"
234235

235236

236237

internal/functions/Get-AllDatabaseInfo.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ function Get-AllDatabaseInfo {
6060
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autocloseexclude' -Value (Get-DbcConfigValue policy.autoclose.excludedb)
6161
}
6262

63+
'AutoShrink' {
64+
$autoshrink = $true
65+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoshrink' -Value (Get-DbcConfigValue policy.database.autoshrink)
66+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoshrinkexclude' -Value (Get-DbcConfigValue policy.autoshrinke.excludedb)
67+
}
68+
6369
'ValidDatabaseOwner' {
6470
$owner = $true
6571
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'validdbownername' -Value (Get-DbcConfigValue policy.validdbowner.name)
@@ -103,6 +109,7 @@ function Get-AllDatabaseInfo {
103109
AsymmetricKeySize = if ($asymmetrickey) { ($psitem.AsymmetricKeys | Where-Object { $_.KeyLength -lt 2048} | Measure-Object).Count }
104110
#AsymmetricKeySize = if ($asymmetrickey) { $psitem.AsymmetricKeys.KeyLength } # doing this I got $null if there wasn't a key
105111
AutoClose = if ($autoclose) { $psitem.AutoClose}
112+
AutoShrink = if ($autoshrink) { $psitem.AutoShrink}
106113
}
107114
}
108115
}

0 commit comments

Comments
 (0)