Skip to content

Install-DbaWhoIsActive - Select version-appropriate SQL file based on server version#10341

Open
andreasjordan wants to merge 3 commits intodevelopmentfrom
claude/issue-10339-20260410-0757
Open

Install-DbaWhoIsActive - Select version-appropriate SQL file based on server version#10341
andreasjordan wants to merge 3 commits intodevelopmentfrom
claude/issue-10339-20260410-0757

Conversation

@andreasjordan
Copy link
Copy Markdown
Collaborator

Implements version-based SQL file selection for sp_WhoIsActive to support the new multi-script release structure.

The SQL file selection is moved from the begin block to the process block so each target server gets the correct script version based on its VersionMajor property. Subfolder matching parses year ranges from directory names (e.g. "2005-2008") and checks whether the server's release year falls within that range.

Closes #10339

Generated with Claude Code

… server version

sp_WhoIsActive now ships version-specific scripts in subfolders named
with year ranges (e.g. 2005-2008, 2012-2019). The root file targets
the latest SQL Server version.

The SQL file selection is moved from the begin block to the process
block so each target server gets the correct script version based on
its VersionMajor property. Subfolder matching parses year ranges
from directory names (e.g. "2005-2008") and checks whether the
server's release year falls within that range.

Closes #10339

(do Install-DbaWhoIsActive)

Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
@andreasjordan
Copy link
Copy Markdown
Collaborator Author

andreasjordan commented Apr 12, 2026

@claude the folder structure is different than expected.

This is the new structure:

Folder "2008" with the files for "SQL Server 2005 - 2008 compatible version":

  • README.md
  • sp_WhoIsActive.sql

Folder "2019" with the files for "SQL Server 2012 - 2019 compatible version":

  • README.md
  • sp_WhoIsActive.sql

Base folder with the files for current versions (2022+):

  • .gitattributes
  • LICENSE
  • README.md
  • sp_WhoIsActive.sql

@claude
Copy link
Copy Markdown

claude bot commented Apr 12, 2026

Claude finished @andreasjordan's task in 1m 43s —— View job


Updating SQL file selection logic for actual folder structure

  • Read current implementation
  • Understand the new folder structure (2008, 2019, base)
  • Update the version-matching logic
  • Commit and push changes

The matching logic has been updated. The folder name (e.g. 2008, 2019) represents the maximum SQL Server release year that folder's script supports. The updated logic:

  1. Filters subfolders to only those with exactly 4-digit names
  2. Sorts them ascending by year
  3. Picks the first subfolder where serverYear ≤ folderYear
  4. Falls back to the root file when the server is newer than all subfolders (2022+)
Server version Year Folder selected
SQL 2005 2005 2008/sp_WhoIsActive.sql
SQL 2008 2008 2008/sp_WhoIsActive.sql
SQL 2012 2012 2019/sp_WhoIsActive.sql
SQL 2019 2019 2019/sp_WhoIsActive.sql
SQL 2022 2022 sp_WhoIsActive.sql (root)
SQL 2025 2025 sp_WhoIsActive.sql (root)

Committed as 70ba714.
|

…folder names (2008, 2019)

Folder names represent the maximum supported SQL Server year, not ranges.
Sort subfolders ascending and pick the first where serverYear <= folderYear.

(do Install-DbaWhoIsActive)

Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
@andreasjordan
Copy link
Copy Markdown
Collaborator Author

@claude I think this is to much code and to much flexibility. Let's only test:

  • if version 2008 or older - use folder 2008
  • if version 2019 or older - use folder 2019
  • else use base folder

Just in case no file is found or the folder is not present then try to find the old "who_is_active.sql" file.

@claude
Copy link
Copy Markdown

claude bot commented Apr 12, 2026

Claude finished @andreasjordan's task in 2m 16s —— View job


Simplifying version selection logic

  • Read current implementation
  • Simplify SQL file selection to hardcoded version checks
  • Commit and push changes

The SQL file selection logic has been replaced with a simple 3-branch check:

if ($server.VersionMajor -le 10) {
    # SQL Server 2008 or older -> folder 2008
} elseif ($server.VersionMajor -le 15) {
    # SQL Server 2012-2019 -> folder 2019
} else {
    # SQL Server 2022+ -> base folder
}

If the resolved file doesn't exist, it falls back to searching for the old who_is_active.sql filename anywhere under the cache directory. Removed ~32 lines of dynamic folder-parsing code.

Committed as 6255edb.
|

Replace flexible dynamic folder parsing with simple hardcoded checks:
- VersionMajor <= 10 (SQL 2008 or older) -> folder 2008
- VersionMajor <= 15 (SQL 2019 or older) -> folder 2019
- Else (SQL 2022+) -> base folder
Falls back to old who_is_active.sql filename if no file is found.

(do Install-DbaWhoIsActive)

Co-authored-by: Andreas Jordan <andreasjordan@users.noreply.github.com>
@andreasjordan andreasjordan marked this pull request as ready for review April 12, 2026 18:15
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.

Install-DbaWhoIsActive - sp_whoisactive versioning change

1 participant