Skip to content

Get-DbaDbTable - Make IncludeSystemDBs actually exclude system databases by default - #10610

Open
andreasjordan wants to merge 1 commit into
developmentfrom
fix-getdbadbtable-includesystemdbs
Open

Get-DbaDbTable - Make IncludeSystemDBs actually exclude system databases by default#10610
andreasjordan wants to merge 1 commit into
developmentfrom
fix-getdbadbtable-includesystemdbs

Conversation

@andreasjordan

Copy link
Copy Markdown
Collaborator

Problem

Get-DbaDbTable declares -IncludeSystemDBs and 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 -Database given), the internal Get-DbaDatabase call now passes -ExcludeSystem unless -IncludeSystemDBs is set. The call was converted to a splat per the style guide.

The semantics follow Get-DbaDbEncryption: a database requested explicitly with -Database is always honored, whether it is a system database or not. This keeps Get-DbaDbTable -Database msdb -Table backupset working without the switch, and keeps the in-repo caller in Install-DbaMaintenanceSolution (which passes -Database together with -IncludeSystemDBs) working unchanged. The help now states this explicitly.

What deliberately did not change

  • The pipeline path (-InputObject) is untouched: piped database objects are the caller's explicit selection.
  • This is a behavior change for callers who relied on the buggy default returning system tables in a full scan — but it is the behavior the parameter and its documentation have promised since the parameter was introduced.

Tests

Added a "System database handling" context: default scan contains no msdb tables, -IncludeSystemDBs brings them back, and an explicit -Database msdb works 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

…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant