Remove-DbaAgDatabase - Honor the AvailabilityGroup filter - #10608
Open
andreasjordan wants to merge 2 commits into
Open
Remove-DbaAgDatabase - Honor the AvailabilityGroup filter#10608andreasjordan wants to merge 2 commits into
andreasjordan wants to merge 2 commits into
Conversation
…Database The parameter was declared and documented but never used, so a removal scoped to one availability group removed the database from whatever availability group it was in. The regression test scopes a removal to a second availability group and asserts the database survives. Found via static analysis by @greenmtnsun in #10607. (do Remove-DbaAgDatabase)
…oes not require The error text told the user to specify one or more availability groups, but the condition only ever required -Database. The AvailabilityGroup parameter is an optional filter. (do Remove-DbaAgDatabase)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Remove-DbaAgDatabasedeclares and documents-AvailabilityGroup("Limits the operation to databases within specific availability groups") but never uses it. The internalGet-DbaAgDatabasecall only received-Database, so a removal scoped to one availability group removed the database from whatever availability group actually contained it.What changed
The
-AvailabilityGroupparameter is now passed through toGet-DbaAgDatabase, which already supported it. The call was converted to a splat per the style guide.What deliberately did not change
-InputObject) is untouched: piped objects are already the caller's explicit selection.-SqlInstancepath used to demand "one or more Availability Groups" although the check only requires-Database; a follow-up commit on this branch corrects the wording to match what is actually required.Tests
Added a regression test that creates a second availability group, scopes a removal to it, and asserts the database in the first availability group survives and nothing is returned. Verified against the lab HADR instance (SQL Server 2025): the new test fails on the old code with exactly the reported behavior (
Status=Removedfor the out-of-scope database) and the full file passes with the fix (4/4).Found by @greenmtnsun via static analysis, reported in #10607.
🤖 Generated with Claude Code