Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get- and Copy-DbaDbQueryStoreOption: Fix DBNull issue and add missing Notes property #9409

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading