|
1 | 1 | # CLAUDE.md |
2 | 2 |
|
3 | | -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository and the dbatools repository which is also in the workspace. |
4 | 4 |
|
5 | 5 | ## Overview |
6 | 6 |
|
@@ -148,4 +148,97 @@ Custom parameter types with validation: |
148 | 148 | - Use `Test-DbatoolsAssemblyLoading` to diagnose assembly issues |
149 | 149 | - The `private/assembly-troubleshoot.ps1` contains helpful diagnostic functions |
150 | 150 | - Build script paths are hardcoded to `C:\github\dbatools.library\` - adjust for your environment |
151 | | -- Assembly loading happens at module import time - use `Import-Module -Force` when testing changes |
| 151 | +- Assembly loading happens at module import time - use `Import-Module -Force` when testing changes |
| 152 | + |
| 153 | +# dbatools folder |
| 154 | + |
| 155 | +# CLAUDE.md |
| 156 | + |
| 157 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 158 | + |
| 159 | +## Development Commands |
| 160 | + |
| 161 | +### Testing |
| 162 | +```powershell |
| 163 | +# Run all tests |
| 164 | +.\tests\appveyor.pester.ps1 |
| 165 | +
|
| 166 | +# Run tests with code coverage |
| 167 | +.\tests\appveyor.pester.ps1 -IncludeCoverage |
| 168 | +
|
| 169 | +# Run specific test file |
| 170 | +Invoke-Pester ./tests/Get-DbaDatabase.Tests.ps1 |
| 171 | +
|
| 172 | +# Finalize test results |
| 173 | +.\tests\appveyor.pester.ps1 -Finalize |
| 174 | +``` |
| 175 | + |
| 176 | +### Development Setup |
| 177 | +```powershell |
| 178 | +# Enable debugging mode before importing |
| 179 | +$dbatools_dotsourcemodule = $true |
| 180 | +Import-Module ./dbatools.psd1 |
| 181 | +
|
| 182 | +# Format code to match project standards (OTBS) |
| 183 | +Invoke-DbatoolsFormatter -Path ./public/YourFunction.ps1 |
| 184 | +``` |
| 185 | + |
| 186 | +### Module Dependencies |
| 187 | +- Primary dependency: `dbatools.library` module (contains SMO and other libraries) |
| 188 | +- Install with: `Install-Module dbatools.library -Scope CurrentUser` |
| 189 | + |
| 190 | +## Architecture Overview |
| 191 | + |
| 192 | +### Core Structure |
| 193 | +- **public/**: All user-facing commands (600+ functions). Each command is in its own file. |
| 194 | +- **private/**: Internal functions organized by purpose: |
| 195 | + - **functions/**: Core internal helpers like `Connect-DbaInstance`, `Stop-Function` |
| 196 | + - **configurations/**: Module settings organized by topic (sql.ps1, logging.ps1, etc.) |
| 197 | + - **dynamicparams/**: Dynamic parameter definitions for tab completion |
| 198 | + - **maintenance/**: Background tasks and runspace management |
| 199 | +- **bin/**: Resources including XE templates, diagnostic queries, build references |
| 200 | +- **tests/**: Pester tests matching public function names |
| 201 | + |
| 202 | +### Key Patterns |
| 203 | + |
| 204 | +#### Command Standards |
| 205 | +- **Naming**: `Verb-DbaObjectType` (e.g., `Get-DbaDatabase`, `Set-DbaSpConfigure`) |
| 206 | +- **Common Parameters**: |
| 207 | + - `-SqlInstance`: Always accepts array of instances |
| 208 | + - `-SqlCredential`: PSCredential for SQL authentication |
| 209 | + - `-EnableException`: Shows full exception details instead of warnings |
| 210 | + - Always implement `-WhatIf`/`-Confirm` for destructive operations |
| 211 | + |
| 212 | +#### Coding Conventions |
| 213 | +- **Parameters**: PascalCase, always singular (`$SqlInstance`, not `$SqlInstances`) |
| 214 | +- **Variables**: camelCase for multi-word (`$currentLogin`) |
| 215 | +- **Error Handling**: Use `Stop-Function` for consistent error management |
| 216 | +- **Output**: Use `Select-DefaultView` to control default property display |
| 217 | +- **Connections**: Always use `Connect-DbaInstance` for SQL connections |
| 218 | + |
| 219 | +#### Internal Functions |
| 220 | +- `Connect-DbaInstance`: Centralizes all SQL Server connections with retry logic |
| 221 | +- `Stop-Function`: Standard error handling with `-EnableException` support |
| 222 | +- `Write-ProgressHelper`: Consistent progress bar implementation |
| 223 | +- `Test-FunctionInterrupt`: Checks for user cancellation in loops |
| 224 | +- `Select-DefaultView`: Controls which properties are displayed by default |
| 225 | + |
| 226 | +### Configuration System |
| 227 | +- Get settings: `Get-DbatoolsConfigValue -Name 'sql.connection.timeout'` |
| 228 | +- Set settings: `Set-DbatoolsConfig -Name 'sql.connection.timeout' -Value 30` |
| 229 | +- Configuration files in `private/configurations/` define module-wide defaults |
| 230 | + |
| 231 | +### Testing Approach |
| 232 | +- Test files must match function names: `Get-DbaDatabase.ps1` → `Get-DbaDatabase.Tests.ps1` |
| 233 | +- Tests use Pester 4/5 compatible syntax |
| 234 | +- AppVeyor CI tests against SQL Server 2008R2, 2016, 2017, 2022 |
| 235 | +- Mock `Connect-DbaInstance` in unit tests to avoid SQL dependencies |
| 236 | + |
| 237 | +### Module Loading |
| 238 | +1. `dbatools.psd1` defines module manifest |
| 239 | +2. `dbatools.psm1` handles initialization: |
| 240 | + - Loads dbatools.library dependency |
| 241 | + - Imports all public/private functions |
| 242 | + - Initializes configuration system |
| 243 | + - Starts maintenance runspaces |
| 244 | +3. Use `$dbatools_dotsourcemodule = $true` before import for debugging |
0 commit comments