Skip to content

Commit

Permalink
fix for #9553
Browse files Browse the repository at this point in the history
  • Loading branch information
jpomfret committed Jan 6, 2025
1 parent 3dba5fd commit 57f49da
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions public/Install-DbaMaintenanceSolution.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function Install-DbaMaintenanceSolution {
https://ola.hallengren.com
.LINK
https://dbatools.io/Install-DbaMaintenanceSolution
https://dbatools.io/Install-DbaMaintenanceSolution
.EXAMPLE
PS C:\> Install-DbaMaintenanceSolution -SqlInstance RES14224 -Database DBA -InstallJobs -CleanupTime 72
Expand Down Expand Up @@ -402,12 +402,6 @@ function Install-DbaMaintenanceSolution {
$cleanupQuery = $null
if ($ReplaceExisting) {
[string]$cleanupQuery = $("
IF OBJECT_ID('[dbo].[CommandLog]', 'U') IS NOT NULL
DROP TABLE [dbo].[CommandLog];
IF OBJECT_ID('[dbo].[QueueDatabase]', 'U') IS NOT NULL
DROP TABLE [dbo].[QueueDatabase];
IF OBJECT_ID('[dbo].[Queue]', 'U') IS NOT NULL
DROP TABLE [dbo].[Queue];
IF OBJECT_ID('[dbo].[CommandExecute]', 'P') IS NOT NULL
DROP PROCEDURE [dbo].[CommandExecute];
IF OBJECT_ID('[dbo].[DatabaseBackup]', 'P') IS NOT NULL
Expand All @@ -418,6 +412,22 @@ function Install-DbaMaintenanceSolution {
DROP PROCEDURE [dbo].[IndexOptimize];
")

if ($LogToTable) {
$cleanupQuery += $("
IF OBJECT_ID('[dbo].[CommandLog]', 'U') IS NOT NULL
DROP TABLE [dbo].[CommandLog];
")
}

if ($InstallParallel) {
$cleanupQuery += $("
IF OBJECT_ID('[dbo].[QueueDatabase]', 'U') IS NOT NULL
DROP TABLE [dbo].[QueueDatabase];
IF OBJECT_ID('[dbo].[Queue]', 'U') IS NOT NULL
DROP TABLE [dbo].[Queue];
")
}

if ($Pscmdlet.ShouldProcess($instance, "Dropping all objects created by Ola's Maintenance Solution")) {
Write-ProgressHelper -ExcludePercent -Message "Dropping objects created by Ola's Maintenance Solution"
$null = $db.Invoke($cleanupQuery)
Expand Down

0 comments on commit 57f49da

Please sign in to comment.