Skip to content

Commit

Permalink
Get- and Copy-DbaDbQueryStoreOption: Fix DBNull issue and add missing…
Browse files Browse the repository at this point in the history
… Notes property (dataplat#9409)
  • Loading branch information
andreasjordan authored Jul 1, 2024
1 parent dfc9e3e commit 1086927
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
23 changes: 9 additions & 14 deletions public/Copy-DbaDbQueryStoreOption.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ function Copy-DbaDbQueryStoreOption {

$sourceDB = Get-DbaDatabase -SqlInstance $sourceServer -Database $SourceDatabase

if ($sourceServer.VersionMajor -eq 14) {
$QueryStoreOptions = $sourceDB.Query("SELECT max_plans_per_query AS MaxPlansPerQuery, wait_stats_capture_mode_desc AS WaitStatsCaptureMode FROM sys.database_query_store_options;", $sourceDB.Name)
} elseif ($sourceServer.VersionMajor -ge 15) {
$QueryStoreOptions = $sourceDB.Query("SELECT max_plans_per_query AS MaxPlansPerQuery, wait_stats_capture_mode_desc AS WaitStatsCaptureMode, capture_policy_execution_count AS CustomCapturePolicyExecutionCount, capture_policy_stale_threshold_hours AS CustomCapturePolicyStaleThresholdHours, capture_policy_total_compile_cpu_time_ms AS CustomCapturePolicyTotalCompileCPUTimeMS, capture_policy_total_execution_cpu_time_ms AS CustomCapturePolicyTotalExecutionCPUTimeMS FROM sys.database_query_store_options;", $sourceDB.Name)
}

foreach ($destinstance in $Destination) {

if (!$DestinationDatabase -and !$Exclude -and !$AllDatabases) {
Expand Down Expand Up @@ -152,6 +146,7 @@ function Copy-DbaDbQueryStoreOption {
DestinationDatabaseID = $destDB.ID
Type = "QueryStore Configuration"
Status = $null
Notes = $null
DateTime = [Dataplat.Dbatools.Utility.DbaDateTime](Get-Date)
}

Expand Down Expand Up @@ -191,8 +186,8 @@ function Copy-DbaDbQueryStoreOption {
CaptureMode = $SourceQSConfig.QueryCaptureMode
CleanupMode = $SourceQSConfig.SizeBasedCleanupMode
StaleQueryThreshold = $SourceQSConfig.StaleQueryThresholdInDays
MaxPlansPerQuery = $QueryStoreOptions.MaxPlansPerQuery
WaitStatsCaptureMode = $QueryStoreOptions.WaitStatsCaptureMode
MaxPlansPerQuery = $SourceQSConfig.MaxPlansPerQuery
WaitStatsCaptureMode = $SourceQSConfig.WaitStatsCaptureMode
}
} elseif ($sourceServer.VersionMajor -ge 15) {
$setDbaDbQueryStoreOptionParameters = @{
Expand All @@ -206,12 +201,12 @@ function Copy-DbaDbQueryStoreOption {
CaptureMode = $SourceQSConfig.QueryCaptureMode
CleanupMode = $SourceQSConfig.SizeBasedCleanupMode
StaleQueryThreshold = $SourceQSConfig.StaleQueryThresholdInDays
MaxPlansPerQuery = $QueryStoreOptions.MaxPlansPerQuery
WaitStatsCaptureMode = $QueryStoreOptions.WaitStatsCaptureMode
CustomCapturePolicyExecutionCount = $QueryStoreOptions.CustomCapturePolicyExecutionCount
CustomCapturePolicyTotalCompileCPUTimeMS = $QueryStoreOptions.CustomCapturePolicyTotalCompileCPUTimeMS
CustomCapturePolicyTotalExecutionCPUTimeMS = $QueryStoreOptions.CustomCapturePolicyTotalExecutionCPUTimeMS
CustomCapturePolicyStaleThresholdHours = $QueryStoreOptions.CustomCapturePolicyStaleThresholdHours
MaxPlansPerQuery = $SourceQSConfig.MaxPlansPerQuery
WaitStatsCaptureMode = $SourceQSConfig.WaitStatsCaptureMode
CustomCapturePolicyExecutionCount = $SourceQSConfig.CustomCapturePolicyExecutionCount
CustomCapturePolicyTotalCompileCPUTimeMS = $SourceQSConfig.CustomCapturePolicyTotalCompileCPUTimeMS
CustomCapturePolicyTotalExecutionCPUTimeMS = $SourceQSConfig.CustomCapturePolicyTotalExecutionCPUTimeMS
CustomCapturePolicyStaleThresholdHours = $SourceQSConfig.CustomCapturePolicyStaleThresholdHours
}
}

Expand Down
4 changes: 2 additions & 2 deletions public/Get-DbaDbQueryStoreOption.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ function Get-DbaDbQueryStoreOption {
$qso = $db.QueryStoreOptions

if ($server.VersionMajor -eq 14) {
$QueryStoreOptions = $db.Query("SELECT max_plans_per_query AS MaxPlansPerQuery, wait_stats_capture_mode_desc AS WaitStatsCaptureMode FROM sys.database_query_store_options;", $db.Name)
$QueryStoreOptions = Invoke-DbaQuery -SqlInstance $server -Database $db.Name -Query "SELECT max_plans_per_query AS MaxPlansPerQuery, wait_stats_capture_mode_desc AS WaitStatsCaptureMode FROM sys.database_query_store_options;" -As PSObject
} elseif ($server.VersionMajor -ge 15) {
$QueryStoreOptions = $db.Query("SELECT max_plans_per_query AS MaxPlansPerQuery, wait_stats_capture_mode_desc AS WaitStatsCaptureMode, capture_policy_execution_count AS CustomCapturePolicyExecutionCount, capture_policy_stale_threshold_hours AS CustomCapturePolicyStaleThresholdHours, capture_policy_total_compile_cpu_time_ms AS CustomCapturePolicyTotalCompileCPUTimeMS, capture_policy_total_execution_cpu_time_ms AS CustomCapturePolicyTotalExecutionCPUTimeMS FROM sys.database_query_store_options;", $db.Name)
$QueryStoreOptions = Invoke-DbaQuery -SqlInstance $server -Database $db.Name -Query "SELECT max_plans_per_query AS MaxPlansPerQuery, wait_stats_capture_mode_desc AS WaitStatsCaptureMode, capture_policy_execution_count AS CustomCapturePolicyExecutionCount, capture_policy_stale_threshold_hours AS CustomCapturePolicyStaleThresholdHours, capture_policy_total_compile_cpu_time_ms AS CustomCapturePolicyTotalCompileCPUTimeMS, capture_policy_total_execution_cpu_time_ms AS CustomCapturePolicyTotalExecutionCPUTimeMS FROM sys.database_query_store_options;" -As PSObject
}

Add-Member -Force -InputObject $qso -MemberType NoteProperty -Name ComputerName -Value $server.ComputerName
Expand Down

0 comments on commit 1086927

Please sign in to comment.