-
-
Notifications
You must be signed in to change notification settings - Fork 860
Refactor all commands that need a dedicated admin connection #10130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Conversation
|
@claude please review this pull request. |
|
Claude finished @andreasjordan's task in 2m 15s —— View job Code Review Complete ✅I've completed a thorough review of this PR. The refactoring introduces a well-designed DAC handling pattern across all affected commands. Here are my findings: OverviewThis PR successfully refactors Critical Issues 🔴1. Incorrect Variable Name in Export FunctionsFiles: These functions use # INCORRECT - parameter doesn't exist
$server = Connect-DbaInstance -SqlInstance $instance -SqlCredential $SourceSqlCredential
# CORRECT - should be
$server = Connect-DbaInstance -SqlInstance $instance -SqlCredential $SqlCredentialThis is likely causing the parameter binding error shown in the GitHub Actions screenshot. Style Guide Issues 🟡2. Hashtable AlignmentMultiple files have hashtables that don't follow the required alignment standard from CLAUDE.md. Example in Copy-DbaCredential.ps1:242-248: # Current (misaligned)
$splatNewCredential = @{
SqlInstance = $destServer
Name = $cred.Name
Identity = $cred.Identity
MappedClassType = $cred.MappedClassType
EnableException = $true
}The equals signs should be perfectly aligned. While this code works, it violates the documented style guide which states: "ALL hashtable assignments must be perfectly aligned." Affected files:
Design & Implementation ✅3. Excellent DAC PatternThe DAC handling pattern is well-designed and consistent: # Determine if DAC is needed
if ($ExcludePassword) { $dacNeeded = $false } else { $dacNeeded = $true }
# Check if already connected via DAC
$dacConnected = $Source.Type -eq 'Server' -and $Source.InputObject.Name -match '^ADMIN:'
# Reuse or open DAC as needed
$dacOpened = $false
if ($dacNeeded) {
if ($dacConnected) {
Write-Message -Level Verbose -Message "Reusing dedicated admin connection..."
$sourceServer = $Source.InputObject
} else {
Write-Message -Level Verbose -Message "Opening dedicated admin connection..."
$sourceServer = Connect-DbaInstance ... -DedicatedAdminConnection
$dacOpened = $true
}
}
# Clean up if we opened it
if ($dacOpened) {
$null = $sourceServer | Disconnect-DbaInstance -WhatIf:$false
}Strengths:
4. Good Code SimplificationThe refactored
5. Proper Parameter AdditionAll commands in the dependency chain correctly added the
The parameter documentation is consistent and clear. Test Updates ✅6. Tests Updated CorrectlyAll affected test files were updated to include the new
This ensures the tests won't fail due to unexpected parameters. Minor Observations 🔵7. Sync-DbaAvailabilityGroup Pipeline HandlingLines 192-202 have interesting logic for pipeline input with DAC: if ($InputObject) {
$dacConnected = $InputObject.Parent.Name -match '^ADMIN:'
if ($dacNeeded -and -not $dacConnected) {
Stop-Function -Message "Pipeline source must use a dedicated admin connection..."
return
}
}This is clever - it requires the piped-in AG object to already have a DAC connection if passwords are needed. This prevents the function from trying to open a second DAC (which would fail). 8. Verbose MessagingExcellent verbose messages throughout:
These will be very helpful for troubleshooting. Recommendations
SummaryThis is a solid refactoring that addresses a real architectural issue. The DAC handling pattern is well-designed, consistent, and properly manages connection lifecycle. Once the variable name issue is fixed, this should be ready to merge. Critical fixes needed: 1 |
|
@claude Thanks for catching the critical issues. They should be fixed now, correct? |
|
Claude finished @andreasjordan's task in 39s —— View job Verifying Fixes
Verification Complete ✅Yes, the critical issues have been fixed correctly! Critical Issue #1 - Variable Name (FIXED) Both files now use the correct parameter name
The previous incorrect usage of Style Issue #2 - Hashtable Alignment I also notice that the hashtable alignment issue I mentioned is not present in these two files in the current code - the hashtables I see are properly aligned or use different patterns. This may have been addressed or may have been in different files. SummaryThe critical parameter binding error that was causing the GitHub Actions failure has been resolved. The code should now work correctly without the "parameter cannot be found" errors. The PR is in good shape from a functional perspective. |
|
Claude is happy, I am happy - so please @potatoqualitee have a look at this. What I don't understand is the gitub action that failes. Maybe it failes because the gallery version has a bug (which hopefully will be fixed by this PR), but as the actions in the other PRs succeed I don't really know. |
|
One test failes on the old AppVeyor-Image: |
|
@potatoqualitee - Should I try to break this PR up into smaller pieces to test and merge them one by one? |
|
I will change with to a draft and move forward in smaller steps starting with #10150 |

Get-DecryptedObjectneeds two things:That's why
Get-DecryptedObjectneeds$Credentialwhich it used all the time, but the parameter was missing.So every command that calls
Get-DecryptedObjectneeds$Credentialas well. This is:So every command that calls one of those commands needs
$Credentialas well. This is:I introduced a new DAC handling in all commands that might open a DAC or call a command that might open a DAC:
When opening a connection we test if we need a DAC and we test if we already have a DAC. We reuse a DAC when possible. We remember if we opened a DAC to later be able to close it.