Get-DbaDbTable - Make IncludeSystemDBs actually exclude system databases by default - #10610
Open
andreasjordan wants to merge 1 commit into
Open
Get-DbaDbTable - Make IncludeSystemDBs actually exclude system databases by default#10610andreasjordan wants to merge 1 commit into
andreasjordan wants to merge 1 commit into
Conversation
…ses by default
The switch was declared and documented ("By default system databases
are excluded") but never used, so a default scan always returned the
tables of master, model, msdb and tempdb. A scan now passes
-ExcludeSystem to Get-DbaDatabase unless -IncludeSystemDBs is set.
Databases requested explicitly with -Database are always honored, like
in Get-DbaDbEncryption, so calls like the one in
Install-DbaMaintenanceSolution keep working.
Found via static analysis by @greenmtnsun in #10607.
(do Get-DbaDbTable)
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
Get-DbaDbTabledeclares-IncludeSystemDBsand its help promises "By default system databases are excluded since they rarely contain user tables of interest" — but the switch was never referenced in the body. A default scan always returned the tables of master, model, msdb and tempdb (151 system tables on a bare lab instance), and the switch changed nothing.What changed
When scanning the instance (no
-Databasegiven), the internalGet-DbaDatabasecall now passes-ExcludeSystemunless-IncludeSystemDBsis set. The call was converted to a splat per the style guide.The semantics follow
Get-DbaDbEncryption: a database requested explicitly with-Databaseis always honored, whether it is a system database or not. This keepsGet-DbaDbTable -Database msdb -Table backupsetworking without the switch, and keeps the in-repo caller inInstall-DbaMaintenanceSolution(which passes-Databasetogether with-IncludeSystemDBs) working unchanged. The help now states this explicitly.What deliberately did not change
-InputObject) is untouched: piped database objects are the caller's explicit selection.Tests
Added a "System database handling" context: default scan contains no msdb tables,
-IncludeSystemDBsbrings them back, and an explicit-Database msdbworks without the switch. Verified in the lab against SQL Server 2019: the default-scan test fails on the old code (msdb found) and the full file passes with the fix (9/9).Found by @greenmtnsun via static analysis, reported in #10607.
🤖 Generated with Claude Code