Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 6, 2025

  • Implement Set-SqlDscDatabaseDefault command with tests and documentation
  • Fix file endings to comply with PowerShell guidelines (must end with one blank line)
  • Replace Should -Not -Throw with direct command calls per Pester guidelines
  • Assign unused return objects to $null as required by instructions
  • Replace New-InvalidOperationException with PSCmdlet.ThrowTerminatingError() per PowerShell guidelines
  • Fix PSCmdlet.ThrowTerminatingError() to properly include the caught exception as inner exception

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


This change is Reviewable

Copilot AI changed the title [WIP] Set-SqlDscDatabaseDefault: New command proposal Add Set-SqlDscDatabaseDefault command for managing database default objects Sep 6, 2025
Copilot AI requested a review from johlju September 6, 2025 11:20
@codecov
Copy link

codecov bot commented Sep 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94%. Comparing base (e86a3d5) to head (e7ba896).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@         Coverage Diff          @@
##           main   #2189   +/-   ##
====================================
  Coverage    94%     94%           
====================================
  Files       131     132    +1     
  Lines      8701    8740   +39     
====================================
+ Hits       8245    8284   +39     
  Misses      456     456           
Flag Coverage Δ
unit 94% <100%> (+<1%) ⬆️
Files with missing lines Coverage Δ
source/Public/Set-SqlDscDatabaseDefault.ps1 100% <100%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI requested a review from johlju September 6, 2025 12:54
@coderabbitai
Copy link

coderabbitai bot commented Sep 6, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a new public PowerShell cmdlet Set-SqlDscDatabaseDefault to set a database's default filegroup, default FILESTREAM filegroup, and default Full‑Text catalog via SMO; includes localization strings, unit and integration tests, SMO test stubs, a changelog entry, and doc/guideline updates.

Changes

Cohort / File(s) Summary
Public cmdlet
source/Public/Set-SqlDscDatabaseDefault.ps1
New Set-SqlDscDatabaseDefault function with ServerObject and DatabaseObject parameter sets; supports ShouldProcess (-WhatIf/-Confirm), optional -Refresh, -Force, -PassThru; invokes SMO SetDefaultFileGroup, SetDefaultFileStreamFileGroup, SetDefaultFullTextCatalog for bound parameters; returns Database when -PassThru; localized messages and error wrapping.
Localization strings
source/en-US/SqlServerDsc.strings.psd1
Adds string resources (DatabaseDefault_*) for operation messages and ShouldProcess captions/descriptions/warnings.
Unit tests & SMO stubs
tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1, tests/Unit/Stubs/SMO.cs
Adds Pester unit tests covering ServerObject and DatabaseObject parameter sets, WhatIf/Confirm, PassThru, success and error cases; extends SMO stub Database with DefaultFileGroup, DefaultFullTextCatalog, and setter methods SetDefaultFileGroup, SetDefaultFileStreamFileGroup, SetDefaultFullTextCatalog to simulate behavior and exceptions.
Integration tests
tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
Adds integration tests that create a temporary DB, filegroup and file; set/reset defaults via DatabaseObject and ServerObject paths; validate via Refresh(); include failure cases and cleanup.
Changelog
CHANGELOG.md
Notes new public command Set-SqlDscDatabaseDefault under Unreleased → Added.
Docs / contributor guidance
.github/*, .github/instructions/*
Rework of contributor/copilot instructions and several style-guideline files; formatting and guidance updates only (no API changes).
Editor settings
.vscode/settings.json
Adds "filegroup" to cSpell.words.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Cmd as Set-SqlDscDatabaseDefault
  participant Server as SMO.Server
  participant DB as SMO.Database

  alt ServerObject parameter set
    User->>Cmd: Invoke -ServerObject Server -Name "db" [params]
    Cmd->>Server: (optional) Server.Databases.Refresh()
    Cmd->>Server: Resolve Database "db"
    Server-->>Cmd: DB or null
    alt not found
      Cmd-->>User: Throw InvalidOperationException (localized)
    end
  else DatabaseObject parameter set
    User->>Cmd: Invoke -DatabaseObject DB [params]
    Cmd->>DB: Validate, get Parent Server
  end

  rect rgba(210,235,255,0.5)
    opt -DefaultFileGroup bound
      Cmd->>DB: SetDefaultFileGroup(name)
    end
    opt -DefaultFileStreamFileGroup bound
      Cmd->>DB: SetDefaultFileStreamFileGroup(name)
    end
    opt -DefaultFullTextCatalog bound
      Cmd->>DB: SetDefaultFullTextCatalog(name)
    end
  end

  alt -PassThru
    DB-->>Cmd: Updated DB
    Cmd-->>User: Return DB
  else no PassThru
    Cmd-->>User: No output
  end

  note over Cmd: Errors during updates wrapped as InvalidOperationException with inner error and localized message
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related issues

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch copilot/fix-2178

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@johlju
Copy link
Member

johlju commented Sep 6, 2025

@coderabbitai review

@johlju johlju marked this pull request as ready for review September 6, 2025 12:58
@johlju johlju requested a review from a team as a code owner September 6, 2025 12:58
@coderabbitai
Copy link

coderabbitai bot commented Sep 6, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@johlju johlju requested a review from Copilot September 6, 2025 12:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new Set-SqlDscDatabaseDefault command for managing database default objects (filegroup, FILESTREAM filegroup, and Full-Text catalog) in SQL Server Database Engine instances. The command supports both server object with database name and direct database object parameter sets.

Key Changes

  • Implements the core Set-SqlDscDatabaseDefault command with full ShouldProcess support
  • Adds comprehensive unit and integration tests covering all functionality
  • Updates SMO stub types to support the new database default operations

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
source/Public/Set-SqlDscDatabaseDefault.ps1 Main command implementation with parameter sets and SMO method calls
tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1 Comprehensive unit tests covering all parameter sets and scenarios
tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 Integration tests validating real SQL Server functionality
tests/Unit/Stubs/SMO.cs Updates to Database class adding properties and methods for default objects
source/en-US/SqlServerDsc.strings.psd1 Localized strings for the new command
CHANGELOG.md Documentation of the new feature

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (10)
CHANGELOG.md (1)

38-43: Entry looks good; please wrap long lines to satisfy MD013.

Wrap the new bullet lines at ≤80 chars (indent 2 spaces for wrapped lines).

-  - Added new command to set default objects of a database in a SQL Server Database Engine instance.
-  - The command can set the default filegroup, default FILESTREAM filegroup, and default Full-Text catalog
-    using SMO methods SetDefaultFileGroup, SetDefaultFileStreamFileGroup, and SetDefaultFullTextCatalog.
-  - Supports both ServerObject with Name parameter set and DatabaseObject parameter set.
+  - Added new command to set default objects of a database in a SQL Server
+    Database Engine instance.
+  - The command can set the default filegroup, default FILESTREAM filegroup,
+    and default Full-Text catalog using SMO methods SetDefaultFileGroup,
+    SetDefaultFileStreamFileGroup, and SetDefaultFullTextCatalog.
+  - Supports both ServerObject with Name parameter set and DatabaseObject
+    parameter set.
tests/Unit/Stubs/SMO.cs (2)

570-572: Good addition of default fields; consider non-null default for FullText.

Initialize DefaultFullTextCatalog to empty to avoid null checks in tests.

-        public string DefaultFullTextCatalog;
+        public string DefaultFullTextCatalog = string.Empty;

623-649: Setter methods LGTM; consider using SMO exceptions for fidelity.

Throw SmoException/FailedOperationException instead of System.Exception to better mimic SMO.

-            if (fileGroupName == "ThrowException")
-            {
-                throw new System.Exception("Failed to set default filegroup");
-            }
+            if (fileGroupName == "ThrowException")
+            {
+                throw new Microsoft.SqlServer.Management.Smo.SmoException(
+                    "Failed to set default filegroup");
+            }
@@
-            if (fileGroupName == "ThrowException")
-            {
-                throw new System.Exception("Failed to set default FILESTREAM filegroup");
-            }
+            if (fileGroupName == "ThrowException")
+            {
+                throw new Microsoft.SqlServer.Management.Smo.SmoException(
+                    "Failed to set default FILESTREAM filegroup");
+            }
@@
-            if (catalogName == "ThrowException")
-            {
-                throw new System.Exception("Failed to set default Full-Text catalog");
-            }
+            if (catalogName == "ThrowException")
+            {
+                throw new Microsoft.SqlServer.Management.Smo.SmoException(
+                    "Failed to set default Full-Text catalog");
+            }
source/en-US/SqlServerDsc.strings.psd1 (1)

374-385: Align grammar with ShouldProcess text (“the database” / “the instance”).

Make these two strings consistent with the ShouldProcess description/caption.

-    DatabaseDefault_Set = Setting default objects of database '{0}' on instance '{1}'. (SSDD0001)
+    DatabaseDefault_Set = Setting default objects of the database '{0}' on the instance '{1}'. (SSDD0001)
@@
-    DatabaseDefault_SetFailed = Failed to set default objects of database '{0}' on instance '{1}'. (SSDD0003)
+    DatabaseDefault_SetFailed = Failed to set default objects of the database '{0}' on the instance '{1}'. (SSDD0003)
tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1 (2)

99-121: Rename It descriptions to avoid “when” per style guide.

“It” descriptions must start with “Should” and must not contain “when”. Suggest concise phrasing.

Apply this diff to update the descriptions:

-        It 'Should set default filegroup when DefaultFileGroup parameter is specified' {
+        It 'Should set default filegroup with DefaultFileGroup parameter' {

-        It 'Should set default FILESTREAM filegroup when DefaultFileStreamFileGroup parameter is specified' {
+        It 'Should set default FILESTREAM filegroup with DefaultFileStreamFileGroup parameter' {

-        It 'Should set default Full-Text catalog when DefaultFullTextCatalog parameter is specified' {
+        It 'Should set default Full-Text catalog with DefaultFullTextCatalog parameter' {

-        It 'Should return database object when PassThru is specified' {
+        It 'Should return database object when PassThru is used' {

-        It 'Should set default filegroup when DefaultFileGroup parameter is specified' {
+        It 'Should set default filegroup with DefaultFileGroup parameter' {

-        It 'Should set default FILESTREAM filegroup when DefaultFileStreamFileGroup parameter is specified' {
+        It 'Should set default FILESTREAM filegroup with DefaultFileStreamFileGroup parameter' {

-        It 'Should set default Full-Text catalog when DefaultFullTextCatalog parameter is specified' {
+        It 'Should set default Full-Text catalog with DefaultFullTextCatalog parameter' {

-        It 'Should return database object when PassThru is specified' {
+        It 'Should return database object when PassThru is used' {

-        It 'Should not modify database when WhatIf is specified' {
+        It 'Should not modify database with WhatIf' {

-        It 'Should not call any SetDefault methods' {
+        It 'Should not call SetDefault methods when no change parameters are provided' {

Also applies to: 122-144, 145-167, 168-191, 210-230, 231-249, 251-269, 271-291, 293-319, 321-343


97-191: Minimize InModuleScope usage for public command tests.

Per guidelines, avoid InModuleScope in public command tests except when accessing $script:localizedData. Most blocks here can run outside InModuleScope; keep it only where localized strings are read (e.g., Database_NotFound).

Also applies to: 210-291, 293-343

tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 (2)

45-52: Add -ErrorAction Stop to surface failures immediately.

Integration tests should pass -ErrorAction Stop to commands under test and related operations.

Apply this diff:

-        $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential
+        $script:serverObject = Connect-SqlDscDatabaseEngine -InstanceName $script:mockInstanceName -Credential $script:mockSqlAdminCredential -ErrorAction 'Stop'

-        $script:testDatabaseObject = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force
+        $script:testDatabaseObject = New-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction 'Stop'

-        Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject
+        Disconnect-SqlDscDatabaseEngine -ServerObject $script:serverObject -ErrorAction 'Stop'

-            $null = Set-SqlDscDatabaseDefault -DatabaseObject $script:testDatabaseObject -DefaultFileGroup $script:testFileGroupName -Force
+            $null = Set-SqlDscDatabaseDefault -DatabaseObject $script:testDatabaseObject -DefaultFileGroup $script:testFileGroupName -Force -ErrorAction 'Stop'
-            $null = Set-SqlDscDatabaseDefault -DatabaseObject $script:testDatabaseObject -DefaultFileGroup 'PRIMARY' -Force
+            $null = Set-SqlDscDatabaseDefault -DatabaseObject $script:testDatabaseObject -DefaultFileGroup 'PRIMARY' -Force -ErrorAction 'Stop'
-            $null = Set-SqlDscDatabaseDefault -ServerObject $script:serverObject -Name $script:testDatabaseName -DefaultFileGroup $script:testFileGroupName -Force
+            $null = Set-SqlDscDatabaseDefault -ServerObject $script:serverObject -Name $script:testDatabaseName -DefaultFileGroup $script:testFileGroupName -Force -ErrorAction 'Stop'
-            $result = Set-SqlDscDatabaseDefault -ServerObject $script:serverObject -Name $script:testDatabaseName -DefaultFileGroup 'PRIMARY' -PassThru -Force
+            $result = Set-SqlDscDatabaseDefault -ServerObject $script:serverObject -Name $script:testDatabaseName -DefaultFileGroup 'PRIMARY' -PassThru -Force -ErrorAction 'Stop'
-            { Set-SqlDscDatabaseDefault -DatabaseObject $script:testDatabaseObject -DefaultFileGroup 'NonExistentFileGroup' -Force } | Should -Throw
+            { Set-SqlDscDatabaseDefault -DatabaseObject $script:testDatabaseObject -DefaultFileGroup 'NonExistentFileGroup' -Force -ErrorAction 'Stop' } | Should -Throw
-            { Set-SqlDscDatabaseDefault -ServerObject $script:serverObject -Name 'NonExistentDatabase' -DefaultFileGroup 'PRIMARY' -Force } | Should -Throw
+            { Set-SqlDscDatabaseDefault -ServerObject $script:serverObject -Name 'NonExistentDatabase' -DefaultFileGroup 'PRIMARY' -Force -ErrorAction 'Stop' } | Should -Throw
-            $null = Remove-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force
+            $null = Remove-SqlDscDatabase -ServerObject $script:serverObject -Name $script:testDatabaseName -Force -ErrorAction 'Stop'

Also applies to: 64-65, 72-76, 80-85, 90-95, 97-103, 108-113, 118-119


37-41: Unused variable.

$script:mockComputerName is assigned but never used. Remove it.

source/Public/Set-SqlDscDatabaseDefault.ps1 (2)

123-133: Use $null on the left side of comparisons.

Style guideline prefers explicit null comparison.

Apply this diff:

-            # Get the database object
-            $DatabaseObject = $ServerObject.Databases[$Name]
-
-            if (-not $DatabaseObject)
+            # Get the database object
+            $DatabaseObject = $ServerObject.Databases[$Name]
+
+            if ($null -eq $DatabaseObject)
             {
                 $errorMessage = $script:localizedData.Database_NotFound -f $Name
                 New-InvalidOperationException -Message $errorMessage
             }

182-185: Refresh before returning to ensure current state in PassThru object.

SMO sometimes requires Refresh() to expose updated properties immediately.

Apply this diff:

-                if ($PassThru.IsPresent)
-                {
-                    return $DatabaseObject
-                }
+                if ($PassThru.IsPresent)
+                {
+                    $DatabaseObject.Refresh()
+                    return $DatabaseObject
+                }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e86a3d5 and 8dadb42.

📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • source/Public/Set-SqlDscDatabaseDefault.ps1 (1 hunks)
  • source/en-US/SqlServerDsc.strings.psd1 (1 hunks)
  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 (1 hunks)
  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1 (1 hunks)
  • tests/Unit/Stubs/SMO.cs (3 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run in PowerShell, from repository root
  • Build before running tests: .\build.ps1 -Tasks build
  • Always run tests in new PowerShell session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Follow guidelines over existing code patterns
  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys; remove any orphaned string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • CHANGELOG.md
  • source/en-US/SqlServerDsc.strings.psd1
  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
  • source/Public/Set-SqlDscDatabaseDefault.ps1
**/*.md

⚙️ CodeRabbit configuration file

**/*.md: # Markdown Style Guidelines

  • Wrap lines at word boundaries when over 80 characters (except tables/code blocks)
  • Use 2 spaces for indentation
  • Use '1.' for all items in ordered lists (1/1/1 numbering style)
  • Disable MD013 rule by adding a comment for tables/code blocks exceeding 80 characters
  • Empty lines required before/after code blocks and headings (except before line 1)
  • Escape backslashes in file paths only (not in code blocks)
  • Code blocks must specify language identifiers

Text Formatting

  • Parameters: bold
  • Values/literals: inline code
  • Resource/module/product names: italic
  • Commands/files/paths: inline code

Files:

  • CHANGELOG.md
CHANGELOG.md

⚙️ CodeRabbit configuration file

CHANGELOG.md: # Changelog Guidelines

  • Always update the Unreleased section in CHANGELOG.md
  • Use Keep a Changelog format
  • Describe notable changes briefly, ≤2 items per change type
  • Reference issues using format issue #<issue_number>
  • No empty lines between list items in same section
  • Do not add item if there are already an existing item for the same change

Files:

  • CHANGELOG.md
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

File naming

  • Class files: ###.ClassName.ps1 format (e.g. 001.SqlReason.ps1, 004.StartupParameters.ps1)

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: Lis...

Files:

  • source/en-US/SqlServerDsc.strings.psd1
  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
  • source/Public/Set-SqlDscDatabaseDefault.ps1
**/*.[Tt]ests.ps1

⚙️ CodeRabbit configuration file

**/*.[Tt]ests.ps1: # Tests Guidelines

Core Requirements

  • All public commands, private functions and classes must have unit tests
  • All public commands and class-based resources must have integration tests
  • Use Pester v5 syntax only
  • Test code only inside Describe blocks
  • Assertions only in It blocks
  • Never test verbose messages, debug messages or parameter binding behavior
  • Pass all mandatory parameters to avoid prompts

Requirements

  • Inside It blocks, assign unused return objects to $null (unless part of pipeline)
  • Tested entity must be called from within the It blocks
  • Keep results and assertions in same It block
  • Avoid try-catch-finally for cleanup, use AfterAll or AfterEach
  • Avoid unnecessary remove/recreate cycles

Naming

  • One Describe block per file matching the tested entity name
  • Context descriptions start with 'When'
  • It descriptions start with 'Should', must not contain 'when'
  • Mock variables prefix: 'mock'

Structure & Scope

  • Public commands: Never use InModuleScope (unless retrieving localized strings)
  • Private functions/class resources: Always use InModuleScope
  • Each class method = separate Context block
  • Each scenario = separate Context block
  • Use nested Context blocks for complex scenarios
  • Mocking in BeforeAll (BeforeEach only when required)
  • Setup/teardown in BeforeAll,BeforeEach/AfterAll,AfterEach close to usage

Syntax Rules

  • PascalCase: Describe, Context, It, Should, BeforeAll, BeforeEach, AfterAll, AfterEach
  • Prefer -BeTrue/-BeFalse over -Be $true/-Be $false
  • Never use Assert-MockCalled, use Should -Invoke instead
  • No Should -Not -Throw - invoke commands directly
  • Never add an empty -MockWith block
  • Omit -MockWith when returning $null
  • Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, InModuleScope:ModuleName
  • Omit -ModuleName parameter on Pester commands
  • Never use Mock inside `InModule...

Files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1

⚙️ CodeRabbit configuration file

tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1: # Integration Tests Guidelines

Requirements

  • Location Commands: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1
  • Location Resources: tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1
  • No mocking - real environment only
  • Cover all scenarios and code paths
  • Use Get-ComputerName for computer names in CI
  • Avoid ExpectedMessage for Should -Throw assertions
  • Only run integration tests in CI unless explicitly instructed.
  • Call commands with -Force parameter where applicable (avoids prompting).
  • Use -ErrorAction Stop on commands so failures surface immediately

Required Setup Block

[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Justification = 'Suppressing this rule because Script Analyzer does not understand Pester syntax.')]
param ()

BeforeDiscovery {
    try
    {
        if (-not (Get-Module -Name 'DscResource.Test'))
        {
            # Assumes dependencies have been resolved, so if this module is not available, run 'noop' task.
            if (-not (Get-Module -Name 'DscResource.Test' -ListAvailable))
            {
                # Redirect all streams to $null, except the error stream (stream 2)
                & "$PSScriptRoot/../../../build.ps1" -Tasks 'noop' 3>&1 4>&1 5>&1 6>&1 > $null
            }

            # If the dependencies have not been resolved, this will throw an error.
            Import-Module -Name 'DscResource.Test' -Force -ErrorAction 'Stop'
        }
    }
    catch [System.IO.FileNotFoundException]
    {
        throw 'DscResource.Test module dependency not found. Please run ".\build.ps1 -ResolveDependency -Tasks build" first.'
    }
}

BeforeAll {
    $script:moduleName = '{MyModuleName}'

    Import-Module -Name $script:moduleName -Force -ErrorAction 'Stop'
}

Files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
source/**/*.ps1

⚙️ CodeRabbit configuration file

source/**/*.ps1: # Localization Guidelines

Requirements

  • Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages
  • Use localized string keys, not hardcoded strings
  • Assume $script:localizedData is available

String Files

  • Commands/functions: source/en-US/{MyModuleName}.strings.psd1
  • Class resources: source/en-US/{ResourceClassName}.strings.psd1

Key Naming Patterns

  • Format: Verb_FunctionName_Action (underscore separators), e.g. Get_Database_ConnectingToDatabase

String Format

ConvertFrom-StringData @'
    KeyName = Message with {0} placeholder. (PREFIX0001)
'@

String IDs

  • Format: (PREFIX####)
  • PREFIX: First letter of each word in class or function name (SqlSetup → SS, Get-SqlDscDatabase → GSDD)
  • Number: Sequential from 0001

Usage

Write-Verbose -Message ($script:localizedData.KeyName -f $value1)

Files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
🧠 Learnings (47)
📚 Learning: 2025-08-29T17:20:42.266Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:20:42.266Z
Learning: Applies to tests/Integration/**/*.ps1 : Use DSCSQLTEST (Database Engine), SSRS (Reporting Services), and PBIRS (Power BI Report Server) instance names in CI integration tests

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:25:09.959Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:25:09.959Z
Learning: Applies to tests/Integration/**/*.Integration.Tests.ps1 : Add integration tests for all public commands and resources

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:20:42.266Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:20:42.266Z
Learning: Applies to tests/Integration/**/*.ps1 : In integration tests requiring a SQL Server DB, use Connect-SqlDscDatabaseEngine with correct CI credentials to open the session

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-08-29T17:20:42.266Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:20:42.266Z
Learning: Applies to tests/Integration/**/*.ps1 : Always call Disconnect-SqlDscDatabaseEngine after Connect-SqlDscDatabaseEngine in integration tests

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:19:40.951Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-29T17:19:40.951Z
Learning: Applies to **/*Integration.Tests.ps1 : Always add and structure Integration tests according to the integration testing guidelines

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-08-29T17:22:07.610Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:22:07.610Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Include the required setup block at the top of each integration test: the SuppressMessage param(), a BeforeDiscovery block that ensures DscResource.Test is available (or runs build.ps1 -Tasks 'noop' and imports it), and a BeforeAll block that sets $script:moduleName and imports the module under test with -Force -ErrorAction Stop

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-08-29T17:20:42.266Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:20:42.266Z
Learning: Applies to tests/Integration/**/*.ps1 : If an integration test requires a SQL Server Database Engine, start the Windows service in BeforeAll and stop it in AfterAll

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-08-29T17:20:42.266Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:20:42.266Z
Learning: Applies to tests/Unit/**/*.ps1 : Unit tests must set $env:SqlServerDscCI = $true in BeforeAll and remove it in AfterAll

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:22:07.610Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:22:07.610Z
Learning: Applies to tests/[iI]ntegration/[cC]ommands/*.[iI]ntegration.[tT]ests.ps1 : Place command integration tests at tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-08-29T17:25:09.959Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:25:09.959Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Place command integration tests in tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1,psd1} : End files with exactly one trailing blank line

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Add one newline after an opening brace

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Add two newlines after a closing brace (one if followed by another brace or continuation)

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : No spaces on empty lines

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Allow at most two consecutive newlines in files

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Separate parameters with a blank line

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Do not commit commented-out code

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-08-29T17:19:40.951Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-29T17:19:40.951Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Follow PowerShell code style guidelines in all PowerShell scripts, modules, and manifests

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Use CRLF line endings

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use one space between keyword and parenthesis (e.g., if ($condition))

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-08-29T17:24:39.268Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:24:39.268Z
Learning: Applies to tests/[u]Unit/**/*.[Tt]ests.ps1 : Include the exact provided Pester setup block before any Describe block (BeforeDiscovery, BeforeAll, AfterAll with defaults and module import/unload)

Applied to files:

  • tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1
📚 Learning: 2025-08-29T17:25:09.959Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:25:09.959Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Add unit tests for all commands, functions, and resources

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:24:39.268Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:24:39.268Z
Learning: Applies to tests/[u]Unit/**/*.[Tt]ests.ps1 : All public commands must have parameter set validation tests

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:24:39.268Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:24:39.268Z
Learning: Applies to tests/[u]Unit/**/*.[Tt]ests.ps1 : Use the provided Parameter Set Validation test template for single-parameter-set commands

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:19:40.951Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-29T17:19:40.951Z
Learning: Applies to **/*Unit.Tests.ps1 : Always add and structure Unit tests according to the unit testing guidelines

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:24:39.268Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-unit-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:24:39.268Z
Learning: Applies to tests/[u]Unit/**/*.[Tt]ests.ps1 : Add Parameter Properties tests (e.g., assert Mandatory on parameters) as shown in the template

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:20:42.266Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:20:42.266Z
Learning: Applies to tests/Unit/**/*.ps1 : In unit tests, use SMO stub types from SMO.cs and never mock real SMO types

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
  • tests/Unit/Stubs/SMO.cs
📚 Learning: 2025-09-05T18:38:09.745Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-05T18:38:09.745Z
Learning: Applies to **/*.[Tt]ests.ps1 : Do not use Should -Not -Throw; invoke commands directly

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:22:07.610Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:22:07.610Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Avoid using ExpectedMessage with Should -Throw assertions in Pester

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-09-05T18:38:09.745Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-05T18:38:09.745Z
Learning: Applies to **/*.[Tt]ests.ps1 : Inside It blocks, assign unused return objects to $null (unless part of pipeline)

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Place $null on the left side of comparisons

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:21:35.582Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md:0-0
Timestamp: 2025-08-29T17:21:35.582Z
Learning: Applies to source/[cC]lasses/**/*.ps1 : Do not use throw for terminating errors; use New-*Exception helpers (New-InvalidDataException, New-ArgumentException, New-InvalidOperationException, New-ObjectNotFoundException, New-InvalidResultException, New-NotImplementedException)

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-09-05T18:38:09.745Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-05T18:38:09.745Z
Learning: Applies to **/*.[Tt]ests.ps1 : Never use Assert-MockCalled; use Should -Invoke instead

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-16T13:35:08.323Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: source/Public/Get-SqlDscLogin.ps1:0-0
Timestamp: 2025-08-16T13:35:08.323Z
Learning: In PowerShell, users expect to receive $null when no objects are found or when a non-terminating error occurs, rather than empty arrays. This is normal PowerShell behavior and should be maintained in DSC commands.

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-09-05T18:38:09.745Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-05T18:38:09.745Z
Learning: Applies to **/*.[Tt]ests.ps1 : It descriptions start with 'Should' and must not contain 'when'

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Avoid empty catch blocks; instead use -ErrorAction SilentlyContinue where appropriate

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-09-05T18:38:09.745Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-05T18:38:09.745Z
Learning: Applies to **/*.[Tt]ests.ps1 : Omit -MockWith when returning $null

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-09-05T18:38:09.745Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-05T18:38:09.745Z
Learning: Applies to **/*.[Tt]ests.ps1 : Use Pester v5 syntax only

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-09-05T18:38:09.745Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-05T18:38:09.745Z
Learning: Applies to **/*.[Tt]ests.ps1 : Avoid try-catch-finally for cleanup; use AfterAll or AfterEach

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:19:40.951Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-29T17:19:40.951Z
Learning: Applies to **/*.Tests.ps1 : Follow test patterns strictly for maintainability in Pester tests

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:22:07.610Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:22:07.610Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : When calling commands in integration tests, pass -Force where applicable to avoid prompts

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-17T10:15:48.194Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: tests/Unit/Public/Remove-SqlDscLogin.Tests.ps1:36-39
Timestamp: 2025-08-17T10:15:48.194Z
Learning: Public command unit tests guideline: Never use InModuleScope unless accessing localized strings from $script:localizedData. PSDefaultParameterValues for InModuleScope should be kept in public command tests to support localized string retrieval when necessary.

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-09-05T18:38:09.745Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-05T18:38:09.745Z
Learning: Applies to **/*.[Tt]ests.ps1 : Set $PSDefaultParameterValues for Mock:ModuleName, Should:ModuleName, InModuleScope:ModuleName

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-09-05T18:38:09.745Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-pester.instructions.md:0-0
Timestamp: 2025-09-05T18:38:09.745Z
Learning: Applies to **/*.[Tt]ests.ps1 : Use $PSDefaultParameterValues only for Pester commands (Describe, Context, It, Mock, Should, InModuleScope)

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-18T13:50:53.789Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2132
File: tests/Unit/Public/New-SqlDscLogin.Tests.ps1:0-0
Timestamp: 2025-08-18T13:50:53.789Z
Learning: In SqlServerDsc unit tests, SMO stub objects can be used to verify method calls like Create() on Login objects by adding mock verifications with Should -Invoke, providing more robust testing than just checking for no exceptions.

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-16T13:22:15.230Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2134
File: tests/Unit/Public/Get-SqlDscLogin.Tests.ps1:78-93
Timestamp: 2025-08-16T13:22:15.230Z
Learning: In PowerShell unit tests for parameter validation in SqlServerDsc, accessing parameter attributes directly like `$cmd.Parameters['ParameterName'].Attributes.Mandatory` works correctly because PowerShell automatically iterates through the array and returns the property values. Additional filtering to ParameterAttribute is not necessary when the parameter structure is known and controlled.

Applied to files:

  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
📚 Learning: 2025-08-29T17:20:42.266Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:20:42.266Z
Learning: Applies to tests/Stubs/SMO.cs : Ensure all SMO types used by unit-tested classes/commands are properly stubbed in SMO.cs

Applied to files:

  • tests/Unit/Stubs/SMO.cs
🪛 markdownlint-cli2 (0.17.2)
CHANGELOG.md

39-39: Line length
Expected: 80; Actual: 100

(MD013, line-length)


40-40: Line length
Expected: 80; Actual: 106

(MD013, line-length)


42-42: Line length
Expected: 80; Actual: 88

(MD013, line-length)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (7)
source/en-US/SqlServerDsc.strings.psd1 (1)

374-385: Keys and ShouldProcess pattern look correct.

Strings cover description, warning, and caption; no trailing period on caption.

Please confirm these keys are referenced by source/Public/Set-SqlDscDatabaseDefault.ps1 and there are no orphaned/duplicate keys in the PSD1.

tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1 (3)

26-50: Good unit-test scaffolding and CI guard.

Imports, SMO stubs loading, PSDefaultParameterValues, and $env:SqlServerDscCI handling look correct.


52-74: Solid parameter-set and parameter-attributes validation.

These checks align with the unit test guidelines for public commands.

Also applies to: 75-88, 90-95


193-207: Error assertion is fine; keep -ExpectedMessage in unit tests only.

This aligns with unit-test guidance (the “no ExpectedMessage” rule applies to integration tests).

tests/Integration/Commands/Set-SqlDscDatabaseDefault.Integration.Tests.ps1 (1)

32-35: Required integration test scaffold present.

Setup/teardown blocks, module import, and service start/stop look correct.

Also applies to: 62-68

source/Public/Set-SqlDscDatabaseDefault.ps1 (2)

64-111: Public command surface and parameter design look correct.

Approved verbs, parameter sets, typing, and help/outputs align with guidelines.


146-152: ShouldProcess placement and update logic LGTM.

Checks are immediately before state changes and only mutate when change parameters are bound.

Also applies to: 154-176, 177-186

Copilot AI requested a review from johlju September 6, 2025 13:24
@johlju
Copy link
Member

johlju commented Sep 6, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Sep 6, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
source/Public/Set-SqlDscDatabaseDefault.ps1 (1)

135-139: Replace New-InvalidOperationException with ThrowTerminatingError (per guidelines)

Functions must use $PSCmdlet.ThrowTerminatingError() for terminating errors. Emit ObjectNotFound for a missing database. This was also requested previously.

Apply:

-            if (-not $DatabaseObject)
-            {
-                $errorMessage = $script:localizedData.Database_NotFound -f $Name
-                New-InvalidOperationException -Message $errorMessage
-            }
+            if (-not $DatabaseObject)
+            {
+                $errorMessage = $script:localizedData.Database_NotFound -f $Name
+
+                $PSCmdlet.ThrowTerminatingError(
+                    [System.Management.Automation.ErrorRecord]::new(
+                        [System.Management.Automation.ItemNotFoundException]::new($errorMessage),
+                        'SSDDD0002', # cSpell: disable-line
+                        [System.Management.Automation.ErrorCategory]::ObjectNotFound,
+                        $Name
+                    )
+                )
+            }
🧹 Nitpick comments (8)
.github/instructions/dsc-community-style-guidelines-powershell.instructions.md (2)

82-82: Tighten wording: remove hyphen and add article

“Inside $PSCmdlet.ShouldProcess-block” → “Inside the $PSCmdlet.ShouldProcess block”.

Apply:

-  - Inside `$PSCmdlet.ShouldProcess`-block, avoid using `Write-Verbose`
+  - Inside the `$PSCmdlet.ShouldProcess` block, avoid using `Write-Verbose`

93-94: Clarify guidance for terminating errors

Improve grammar and explicitly mention InnerException handling in try/catch.

Apply:

-  - Use `$PSCmdlet.ThrowTerminatingError()` for terminating errors (except for classes), use relevant error category, in try-catch include exception
+  - Use `$PSCmdlet.ThrowTerminatingError()` for terminating errors (except in classes) with a relevant error category; in try/catch, include the caught exception as the InnerException
.github/instructions/dsc-community-style-guidelines.instructions.md (2)

24-34: Fix markdown lint MD032: add blank lines around list

Surround the Requirements list with blank lines to satisfy MD032.

Apply:

 ## Requirements
- - Follow instructions over existing code patterns
+ 
+ - Follow instructions over existing code patterns
   - Follow PowerShell style and test guideline instructions strictly
   - Always update CHANGELOG.md Unreleased section
   - Localize all strings using string keys; remove any orphaned string keys
   - Check DscResource.Common before creating private functions
   - Separate reusable logic into private functions
   - DSC resources should always be created as class-based resources
   - Add unit tests for all commands/functions/resources
   - Add integration tests for all public commands and resources
+ 

26-27: Grammar: make “guideline instructions” concise

Use “the PowerShell style and test guidelines”.

Apply:

- - Follow PowerShell style and test guideline instructions strictly
+ - Follow the PowerShell style and test guidelines strictly
source/en-US/SqlServerDsc.strings.psd1 (2)

374-397: Strings look consistent; minor prefix consistency nit

Keys, placeholders, and caption punctuation look correct and localized. One nit: the error id used in code is ‘SSDDD0001’ while these messages use the prefix ‘SSDD’. Consider aligning the error id prefix with the message prefix for consistency in diagnostics.


374-397: Remove unused localization keys
The following DatabaseDefault_* entries in source/en-US/SqlServerDsc.strings.psd1 aren’t referenced by any .ps1 or .psm1 under source/ and should be removed (or hooked up if they were intended for future use):

  • DatabaseDefault_Set_ShouldProcessCaption
  • DatabaseDefault_Set_ShouldProcessVerboseDescription
  • DatabaseDefault_Set_ShouldProcessVerboseWarning
source/Public/Set-SqlDscDatabaseDefault.ps1 (2)

157-169: Avoid Write-Verbose inside ShouldProcess blocks

Guidelines now say to avoid Write-Verbose inside the $PSCmdlet.ShouldProcess block. Keep the gating and remove the inner Verbose lines; rely on ShouldProcess messaging plus the final “Updated” verbose.

Apply:

-                if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
-                {
-                    Write-Verbose -Message ($script:localizedData.DatabaseDefault_UpdatingDefaultFileGroup -f $DefaultFileGroup)
-                    $DatabaseObject.SetDefaultFileGroup($DefaultFileGroup)
-                    $wasUpdate = $true
-                }
+                if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
+                {
+                    $DatabaseObject.SetDefaultFileGroup($DefaultFileGroup)
+                    $wasUpdate = $true
+                }
@@
-                if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
-                {
-                    Write-Verbose -Message ($script:localizedData.DatabaseDefault_UpdatingDefaultFileStreamFileGroup -f $DefaultFileStreamFileGroup)
-                    $DatabaseObject.SetDefaultFileStreamFileGroup($DefaultFileStreamFileGroup)
-                    $wasUpdate = $true
-                }
+                if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
+                {
+                    $DatabaseObject.SetDefaultFileStreamFileGroup($DefaultFileStreamFileGroup)
+                    $wasUpdate = $true
+                }
@@
-                if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
-                {
-                    Write-Verbose -Message ($script:localizedData.DatabaseDefault_UpdatingDefaultFullTextCatalog -f $DefaultFullTextCatalog)
-                    $DatabaseObject.SetDefaultFullTextCatalog($DefaultFullTextCatalog)
-                    $wasUpdate = $true
-                }
+                if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
+                {
+                    $DatabaseObject.SetDefaultFullTextCatalog($DefaultFullTextCatalog)
+                    $wasUpdate = $true
+                }

Note: This applies the “ShouldProcess immediately before state change” rule and the new “avoid Write-Verbose inside ShouldProcess” guidance captured in the retrieved learnings.

Also applies to: 171-183, 185-197


153-168: Optional: no-op guard when no default parameters are supplied

If none of DefaultFileGroup/DefaultFileStreamFileGroup/DefaultFullTextCatalog are bound, consider emitting a localized Write-Verbose (or Write-Information) saying “no changes specified” and return early.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c25798a and 75fb8d8.

📒 Files selected for processing (5)
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md (2 hunks)
  • .github/instructions/dsc-community-style-guidelines.instructions.md (1 hunks)
  • CHANGELOG.md (2 hunks)
  • source/Public/Set-SqlDscDatabaseDefault.ps1 (1 hunks)
  • source/en-US/SqlServerDsc.strings.psd1 (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG.md
🧰 Additional context used
📓 Path-based instructions (3)
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run in PowerShell, from repository root
  • Build before running tests: .\build.ps1 -Tasks build
  • Always run tests in new PowerShell session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Follow instructions over existing code patterns
  • Follow PowerShell style and test guideline instructions strictly
  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys; remove any orphaned string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • DSC resources should always be created as class-based resources
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
  • source/en-US/SqlServerDsc.strings.psd1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

File naming

  • Class files: ###.ClassName.ps1 format (e.g. 001.SqlReason.ps1, 004.StartupParameters.ps1)

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: Lis...

Files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
  • source/en-US/SqlServerDsc.strings.psd1
source/**/*.ps1

⚙️ CodeRabbit configuration file

source/**/*.ps1: # Localization Guidelines

Requirements

  • Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages
  • Use localized string keys, not hardcoded strings
  • Assume $script:localizedData is available

String Files

  • Commands/functions: source/en-US/{MyModuleName}.strings.psd1
  • Class resources: source/en-US/{ResourceClassName}.strings.psd1

Key Naming Patterns

  • Format: Verb_FunctionName_Action (underscore separators), e.g. Get_Database_ConnectingToDatabase

String Format

ConvertFrom-StringData @'
    KeyName = Message with {0} placeholder. (PREFIX0001)
'@

String IDs

  • Format: (PREFIX####)
  • PREFIX: First letter of each word in class or function name (SqlSetup → SS, Get-SqlDscDatabase → GSDD)
  • Number: Sequential from 0001

Usage

Write-Verbose -Message ($script:localizedData.KeyName -f $value1)

Files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
🧠 Learnings (48)
📚 Learning: 2025-08-29T17:21:35.582Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md:0-0
Timestamp: 2025-08-29T17:21:35.582Z
Learning: Applies to source/[cC]lasses/**/*.ps1 : These guidelines apply only to classes decorated with [DscResource(...)]

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:19:40.951Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-29T17:19:40.951Z
Learning: Create new DSC resources as class-based resources and follow class-based resource guidelines

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:19:40.951Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-29T17:19:40.951Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Follow PowerShell code style guidelines in all PowerShell scripts, modules, and manifests

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-29T17:19:40.951Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-29T17:19:40.951Z
Learning: SqlServerDsc-specific guidelines override general project guidelines

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:19:40.951Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-29T17:19:40.951Z
Learning: Follow SqlServerDsc project-specific guidelines

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:21:35.582Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md:0-0
Timestamp: 2025-08-29T17:21:35.582Z
Learning: Applies to source/[cC]lasses/**/*.ps1 : Comment-based help: In .DESCRIPTION include '## Requirements' and '## Known issues' with link pattern to all open issues for {ResourceName}

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:25:09.959Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:25:09.959Z
Learning: Applies to tests/Integration/**/*.Integration.Tests.ps1 : Add integration tests for all public commands and resources

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:19:40.951Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-29T17:19:40.951Z
Learning: Applies to **/*Integration.Tests.ps1 : Always add and structure Integration tests according to the integration testing guidelines

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:25:09.959Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:25:09.959Z
Learning: Applies to tests/Integration/Commands/*.Integration.Tests.ps1 : Place command integration tests in tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:22:07.610Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:22:07.610Z
Learning: Applies to tests/[iI]ntegration/[cC]ommands/*.[iI]ntegration.[tT]ests.ps1 : Place command integration tests at tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:22:07.610Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:22:07.610Z
Learning: Applies to tests/[iI]ntegration/[rR]esources/*.[iI]ntegration.[tT]ests.ps1 : Place resource integration tests at tests/Integration/Resources/{ResourceName}.Integration.Tests.ps1

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:20:42.266Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/SqlServerDsc-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:20:42.266Z
Learning: Applies to tests/Integration/{Commands,Resources}/README.md : Follow integration test configuration guidance documented in tests/Integration/Commands/README.md and tests/Integration/Resources/README.md

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:22:07.610Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:22:07.610Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Include the required setup block at the top of each integration test: the SuppressMessage param(), a BeforeDiscovery block that ensures DscResource.Test is available (or runs build.ps1 -Tasks 'noop' and imports it), and a BeforeAll block that sets $script:moduleName and imports the module under test with -Force -ErrorAction Stop

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:25:09.959Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines.instructions.md:0-0
Timestamp: 2025-08-29T17:25:09.959Z
Learning: Applies to tests/Unit/**/*.Tests.ps1 : Add unit tests for all commands, functions, and resources

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:22:07.610Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-integration-tests.instructions.md:0-0
Timestamp: 2025-08-29T17:22:07.610Z
Learning: Applies to tests/[iI]ntegration/**/*.[iI]ntegration.[tT]ests.ps1 : Ensure integration tests cover all scenarios and code paths

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-08-29T17:19:40.951Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-29T17:19:40.951Z
Learning: Applies to **/*Unit.Tests.ps1 : Always add and structure Unit tests according to the unit testing guidelines

Applied to files:

  • .github/instructions/dsc-community-style-guidelines.instructions.md
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1,psd1} : End files with exactly one trailing blank line

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Add two newlines after a closing brace (one if followed by another brace or continuation)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Add one newline after an opening brace

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Separate parameters with a blank line

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : No spaces on empty lines

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Place opening brace on a new line (except in variable assignments)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Allow at most two consecutive newlines in files

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use one space between keyword and parenthesis (e.g., if ($condition))

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Use CRLF line endings

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use 'param ()' if no parameters; otherwise put opening/closing parentheses on their own lines

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use $PSCmdlet.ThrowTerminatingError() for terminating errors (except in classes) with a relevant error category

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-25T10:07:22.349Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-08-25T10:07:22.349Z
Learning: Applies to source/DSCResources/**/*.psm1 : Do not use throw for terminating errors; handle errors via try/catch

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-29T17:21:35.582Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md:0-0
Timestamp: 2025-08-29T17:21:35.582Z
Learning: Applies to source/[cC]lasses/**/*.ps1 : Do not use throw for terminating errors; use New-*Exception helpers (New-InvalidDataException, New-ArgumentException, New-InvalidOperationException, New-ObjectNotFoundException, New-InvalidResultException, New-NotImplementedException)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use Write-Error for non-terminating errors with a relevant error category

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-25T10:07:22.349Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-08-25T10:07:22.349Z
Learning: Applies to source/DSCResources/**/*.psm1 : When raising terminating errors, throw localized exceptions created via the appropriate DscResource.Common New-*Exception cmdlets (e.g., New-InvalidDataException, New-ArgumentException, New-InvalidOperationException, New-ObjectNotFoundException, New-InvalidResultException, New-NotImplementedException)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : For state-changing functions, use [CmdletBinding(SupportsShouldProcess=$true)] and call $PSCmdlet.ShouldProcess immediately before each state change, following the required message pattern

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Set $ErrorActionPreference = 'Stop' before commands using -ErrorAction 'Stop', then restore after

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-29T17:21:35.582Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md:0-0
Timestamp: 2025-08-29T17:21:35.582Z
Learning: Applies to source/[cC]lasses/**/*.ps1 : Use try/catch for error handling in resource methods

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Avoid empty catch blocks; instead use -ErrorAction SilentlyContinue where appropriate

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use Write-Warning for non-fatal issues, deprecated usage, and configuration problems that don't block execution

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use the ShouldProcess required pattern with description, confirmation, and caption messages sourced from localized data and formatted parameters

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-17T10:48:15.384Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-25T10:07:22.349Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-08-25T10:07:22.349Z
Learning: Applies to source/DSCResources/**/*.psm1 : Use localized strings for all user-facing messages (Write-Verbose, Write-Error, etc.)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-29T17:22:23.268Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-08-29T17:22:23.268Z
Learning: Applies to source/**/*.ps1 : Use localized string keys instead of hardcoded strings in script output/messages

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-29T17:22:23.268Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-08-29T17:22:23.268Z
Learning: Applies to source/**/*.ps1 : When emitting messages, reference $script:localizedData.KeyName and format with the -f operator (e.g., Write-Verbose -Message ($script:localizedData.KeyName -f $value1))

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use Write-Verbose for high-level execution flow and user-actionable information

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Avoid Write-Host; prefer Write-Verbose/Write-Information/etc.

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Never use backtick (`) as a line continuation in production code

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Avoid Write-Output; use return instead

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Include a -Force switch when using $PSCmdlet.ShouldContinue or SupportsShouldProcess

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-08-25T10:07:22.349Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-08-25T10:07:22.349Z
Learning: Applies to source/DSCResources/**/*.psm1 : Each of the three functions must call Write-Verbose at least once

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use Write-Information for user-facing status updates, important operational messages, and non-error state changes

Applied to files:

  • .github/instructions/dsc-community-style-guidelines-powershell.instructions.md
🪛 LanguageTool
.github/instructions/dsc-community-style-guidelines.instructions.md

[grammar] ~27-~27: There might be a mistake here.
Context: ...uideline instructions strictly - Always update CHANGELOG.md Unreleased section - Local...

(QB_NEW_EN)

.github/instructions/dsc-community-style-guidelines-powershell.instructions.md

[grammar] ~82-~82: There might be a mistake here.
Context: ...mdlet.ShouldProcess-block, avoid using Write-Verbose` - Never use backtick as line continuation ...

(QB_NEW_EN)

🪛 markdownlint-cli2 (0.17.2)
.github/instructions/dsc-community-style-guidelines.instructions.md

25-25: Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (4)
source/Public/Set-SqlDscDatabaseDefault.ps1 (4)

1-70: Help content is solid

SYNOPSIS/DESCRIPTION/INPUTS/OUTPUTS and examples meet the project’s help structure.


148-151: Force pattern usage looks correct

Good use of the Force/Confirm pattern to suppress confirmation when -Force is present and -Confirm is not.


199-207: PassThru behavior matches OutputType and guidelines

Returns the database object only when requested. LGTM.


209-223: Terminating error includes inner exception and category

Good use of $PSCmdlet.ThrowTerminatingError with an InnerException and a specific category.

@johlju
Copy link
Member

johlju commented Sep 6, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Sep 6, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
source/Public/Set-SqlDscDatabaseDefault.ps1 (2)

222-223: Verify exactly one trailing blank line at EOF

Ensure the file ends with a single blank line per repo style. Run the script below to verify.

#!/bin/bash
set -euo pipefail
f='source/Public/Set-SqlDscDatabaseDefault.ps1'
python - <<'PY'
import pathlib, sys
p = pathlib.Path('source/Public/Set-SqlDscDatabaseDefault.ps1')
b = p.read_bytes()
ok = b.endswith(b'\r\n\r\n') and not b.endswith(b'\r\n\r\n\r\n')
print(f"EOF blank-line check: {'OK' if ok else 'FAIL'}")
sys.exit(0 if ok else 1)
PY

137-139: Use PSCmdlet.ThrowTerminatingError() instead of New-InvalidOperationException for not-found case

Per guidelines for functions, raise terminating errors via PSCmdlet.ThrowTerminatingError with a relevant ErrorCategory. Recommend ObjectNotFound here.

-            if (-not $DatabaseObject)
-            {
-                $errorMessage = $script:localizedData.Database_NotFound -f $Name
-                New-InvalidOperationException -Message $errorMessage
-            }
+            if (-not $DatabaseObject)
+            {
+                $errorMessage = $script:localizedData.Database_NotFound -f $Name
+                $exception = [System.Management.Automation.ItemNotFoundException]::new($errorMessage)
+
+                $PSCmdlet.ThrowTerminatingError(
+                    [System.Management.Automation.ErrorRecord]::new(
+                        $exception,
+                        'SSDDD0002', # cSpell: disable-line
+                        [System.Management.Automation.ErrorCategory]::ObjectNotFound,
+                        $Name
+                    )
+                )
+            }
🧹 Nitpick comments (1)
source/Public/Set-SqlDscDatabaseDefault.ps1 (1)

74-76: Remove empty OutputType attribute

Keep only the concrete return type; the empty [OutputType()] is redundant.

-    [OutputType()]
-    [OutputType([Microsoft.SqlServer.Management.Smo.Database])]
+    [OutputType([Microsoft.SqlServer.Management.Smo.Database])]
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 75fb8d8 and 1c5571b.

📒 Files selected for processing (2)
  • source/Public/Set-SqlDscDatabaseDefault.ps1 (1 hunks)
  • source/en-US/SqlServerDsc.strings.psd1 (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • source/en-US/SqlServerDsc.strings.psd1
🧰 Additional context used
📓 Path-based instructions (3)
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run in PowerShell, from repository root
  • Build before running tests: .\build.ps1 -Tasks build
  • Always run tests in new PowerShell session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Follow instructions over existing code patterns
  • Follow PowerShell style and test guideline instructions strictly
  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys; remove any orphaned string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • DSC resources should always be created as class-based resources
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

File naming

  • Class files: ###.ClassName.ps1 format (e.g. 001.SqlReason.ps1, 004.StartupParameters.ps1)

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: Lis...

Files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
source/**/*.ps1

⚙️ CodeRabbit configuration file

source/**/*.ps1: # Localization Guidelines

Requirements

  • Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages
  • Use localized string keys, not hardcoded strings
  • Assume $script:localizedData is available

String Files

  • Commands/functions: source/en-US/{MyModuleName}.strings.psd1
  • Class resources: source/en-US/{ResourceClassName}.strings.psd1

Key Naming Patterns

  • Format: Verb_FunctionName_Action (underscore separators), e.g. Get_Database_ConnectingToDatabase

String Format

ConvertFrom-StringData @'
    KeyName = Message with {0} placeholder. (PREFIX0001)
'@

String IDs

  • Format: (PREFIX####)
  • PREFIX: First letter of each word in class or function name (SqlSetup → SS, Get-SqlDscDatabase → GSDD)
  • Number: Sequential from 0001

Usage

Write-Verbose -Message ($script:localizedData.KeyName -f $value1)

Files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
🧠 Learnings (25)
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1,psd1} : End files with exactly one trailing blank line

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Add two newlines after a closing brace (one if followed by another brace or continuation)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Add one newline after an opening brace

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Separate parameters with a blank line

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : No spaces on empty lines

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Place opening brace on a new line (except in variable assignments)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Allow at most two consecutive newlines in files

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use one space between keyword and parenthesis (e.g., if ($condition))

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Use CRLF line endings

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use 'param ()' if no parameters; otherwise put opening/closing parentheses on their own lines

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use $PSCmdlet.ThrowTerminatingError() for terminating errors (except in classes) with a relevant error category

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-25T10:07:22.349Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-08-25T10:07:22.349Z
Learning: Applies to source/DSCResources/**/*.psm1 : Do not use throw for terminating errors; handle errors via try/catch

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-29T17:21:35.582Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md:0-0
Timestamp: 2025-08-29T17:21:35.582Z
Learning: Applies to source/[cC]lasses/**/*.ps1 : Do not use throw for terminating errors; use New-*Exception helpers (New-InvalidDataException, New-ArgumentException, New-InvalidOperationException, New-ObjectNotFoundException, New-InvalidResultException, New-NotImplementedException)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use Write-Error for non-terminating errors with a relevant error category

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-25T10:07:22.349Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-08-25T10:07:22.349Z
Learning: Applies to source/DSCResources/**/*.psm1 : When raising terminating errors, throw localized exceptions created via the appropriate DscResource.Common New-*Exception cmdlets (e.g., New-InvalidDataException, New-ArgumentException, New-InvalidOperationException, New-ObjectNotFoundException, New-InvalidResultException, New-NotImplementedException)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : For state-changing functions, use [CmdletBinding(SupportsShouldProcess=$true)] and call $PSCmdlet.ShouldProcess immediately before each state change, following the required message pattern

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Set $ErrorActionPreference = 'Stop' before commands using -ErrorAction 'Stop', then restore after

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-29T17:21:35.582Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md:0-0
Timestamp: 2025-08-29T17:21:35.582Z
Learning: Applies to source/[cC]lasses/**/*.ps1 : Use try/catch for error handling in resource methods

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Avoid empty catch blocks; instead use -ErrorAction SilentlyContinue where appropriate

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use Write-Warning for non-fatal issues, deprecated usage, and configuration problems that don't block execution

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use the ShouldProcess required pattern with description, confirmation, and caption messages sourced from localized data and formatted parameters

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-17T10:48:15.384Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-25T10:07:22.349Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-08-25T10:07:22.349Z
Learning: Applies to source/DSCResources/**/*.psm1 : Use localized strings for all user-facing messages (Write-Verbose, Write-Error, etc.)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-29T17:22:23.268Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-08-29T17:22:23.268Z
Learning: Applies to source/**/*.ps1 : Use localized string keys instead of hardcoded strings in script output/messages

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-29T17:22:23.268Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-08-29T17:22:23.268Z
Learning: Applies to source/**/*.ps1 : When emitting messages, reference $script:localizedData.KeyName and format with the -f operator (e.g., Write-Verbose -Message ($script:localizedData.KeyName -f $value1))

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (3)
source/Public/Set-SqlDscDatabaseDefault.ps1 (3)

153-194: Good: Each state change is individually gated by ShouldProcess using the required pattern

Matches the required description/confirmation/caption variables and placement immediately before each Set* call.


148-151: Force/Confirm pattern looks correct

Pattern aligns with guidelines to suppress confirmation when -Force is used.


1-70: All referenced localization keys exist
All $script:localizedData keys in source/Public/Set-SqlDscDatabaseDefault.ps1 are defined in source/en-US/SqlServerDsc.strings.psd1.

@johlju
Copy link
Member

johlju commented Sep 6, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Sep 6, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
source/Public/Set-SqlDscDatabaseDefault.ps1 (1)

146-195: Optional: emit per-change verbose messages outside the ShouldProcess block

If you want more traceability without violating the “no Write-Verbose inside ShouldProcess” rule, log just before calling ShouldProcess.

             if ($PSBoundParameters.ContainsKey('DefaultFileGroup'))
             {
                 $descriptionMessage = $script:localizedData.DatabaseDefault_SetFileGroup_ShouldProcessVerboseDescription -f $Name, $DefaultFileGroup, $ServerObject.InstanceName
                 $confirmationMessage = $script:localizedData.DatabaseDefault_SetFileGroup_ShouldProcessVerboseWarning -f $Name, $DefaultFileGroup
                 $captionMessage = $script:localizedData.DatabaseDefault_SetFileGroup_ShouldProcessCaption
 
+                Write-Verbose -Message ($script:localizedData.DatabaseDefault_UpdatingDefaultFileGroup -f $DefaultFileGroup)
                 if ($PSCmdlet.ShouldProcess($descriptionMessage, $confirmationMessage, $captionMessage))
                 {
                     $DatabaseObject.SetDefaultFileGroup($DefaultFileGroup)
                     $wasUpdate = $true
                 }
             }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c5571b and e7ba896.

📒 Files selected for processing (3)
  • .vscode/settings.json (1 hunks)
  • source/Public/Set-SqlDscDatabaseDefault.ps1 (1 hunks)
  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1 (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/Unit/Public/Set-SqlDscDatabaseDefault.Tests.ps1
🧰 Additional context used
📓 Path-based instructions (3)
**

⚙️ CodeRabbit configuration file

**: # DSC Community Guidelines

Terminology

  • Command: Public command
  • Function: Private function
  • Resource: DSC class-based resource

Build & Test Workflow

  • Run in PowerShell, from repository root
  • Build before running tests: .\build.ps1 -Tasks build
  • Always run tests in new PowerShell session: Invoke-Pester -Path @({test paths}) -Output Detailed

File Organization

  • Public commands: source/Public/{CommandName}.ps1
  • Private functions: source/Private/{FunctionName}.ps1
  • Unit tests: tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1
  • Integration tests: tests/Integration/Commands/{CommandName}.Integration.Tests.ps1

Requirements

  • Follow instructions over existing code patterns
  • Follow PowerShell style and test guideline instructions strictly
  • Always update CHANGELOG.md Unreleased section
  • Localize all strings using string keys; remove any orphaned string keys
  • Check DscResource.Common before creating private functions
  • Separate reusable logic into private functions
  • DSC resources should always be created as class-based resources
  • Add unit tests for all commands/functions/resources
  • Add integration tests for all public commands and resources

Files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
**/*.ps?(m|d)1

⚙️ CodeRabbit configuration file

**/*.ps?(m|d)1: # PowerShell Guidelines

Naming

  • Use descriptive names (3+ characters, no abbreviations)
  • Functions: PascalCase with Verb-Noun format using approved verbs
  • Parameters: PascalCase
  • Variables: camelCase
  • Keywords: lower-case
  • Classes: PascalCase
  • Include scope for script/global/environment variables: $script:, $global:, $env:

File naming

  • Class files: ###.ClassName.ps1 format (e.g. 001.SqlReason.ps1, 004.StartupParameters.ps1)

Formatting

Indentation & Spacing

  • Use 4 spaces (no tabs)
  • One space around operators: $a = 1 + 2
  • One space between type and variable: [String] $name
  • One space between keyword and parenthesis: if ($condition)
  • No spaces on empty lines
  • Try to limit lines to 120 characters

Braces

  • Newline before opening brace (except variable assignments)
  • One newline after opening brace
  • Two newlines after closing brace (one if followed by another brace or continuation)

Quotes

  • Use single quotes unless variable expansion is needed: 'text' vs "text $variable"

Arrays

  • Single line: @('one', 'two', 'three')
  • Multi-line: each element on separate line with proper indentation
  • Do not use the unary comma operator (,) in return statements to force
    an array

Hashtables

  • Empty: @{}
  • Each property on separate line with proper indentation
  • Properties: Use PascalCase

Comments

  • Single line: # Comment (capitalized, on own line)
  • Multi-line: <# Comment #> format (opening and closing brackets on own line), and indent text
  • No commented-out code

Comment-based help

  • Always add comment-based help to all functions and scripts
  • Comment-based help: SYNOPSIS, DESCRIPTION (40+ chars), PARAMETER, EXAMPLE sections before function/class
  • Comment-based help indentation: keywords 4 spaces, text 8 spaces
  • Include examples for all parameter sets and combinations
  • INPUTS: List each pipeline‑accepted type (one per line) with a 1‑line description.
  • OUTPUTS: Lis...

Files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
source/**/*.ps1

⚙️ CodeRabbit configuration file

source/**/*.ps1: # Localization Guidelines

Requirements

  • Localize all Write-Debug, Write-Verbose, Write-Error, Write-Warning and $PSCmdlet.ThrowTerminatingError() messages
  • Use localized string keys, not hardcoded strings
  • Assume $script:localizedData is available

String Files

  • Commands/functions: source/en-US/{MyModuleName}.strings.psd1
  • Class resources: source/en-US/{ResourceClassName}.strings.psd1

Key Naming Patterns

  • Format: Verb_FunctionName_Action (underscore separators), e.g. Get_Database_ConnectingToDatabase

String Format

ConvertFrom-StringData @'
    KeyName = Message with {0} placeholder. (PREFIX0001)
'@

String IDs

  • Format: (PREFIX####)
  • PREFIX: First letter of each word in class or function name (SqlSetup → SS, Get-SqlDscDatabase → GSDD)
  • Number: Sequential from 0001

Usage

Write-Verbose -Message ($script:localizedData.KeyName -f $value1)

Files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
🧠 Learnings (25)
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1,psd1} : End files with exactly one trailing blank line

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Add two newlines after a closing brace (one if followed by another brace or continuation)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Add one newline after an opening brace

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Separate parameters with a blank line

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : No spaces on empty lines

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Place opening brace on a new line (except in variable assignments)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Allow at most two consecutive newlines in files

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use one space between keyword and parenthesis (e.g., if ($condition))

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1,psd1} : Use CRLF line endings

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use 'param ()' if no parameters; otherwise put opening/closing parentheses on their own lines

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use $PSCmdlet.ThrowTerminatingError() for terminating errors (except in classes) with a relevant error category

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-25T10:07:22.349Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-08-25T10:07:22.349Z
Learning: Applies to source/DSCResources/**/*.psm1 : Do not use throw for terminating errors; handle errors via try/catch

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-29T17:21:35.582Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md:0-0
Timestamp: 2025-08-29T17:21:35.582Z
Learning: Applies to source/[cC]lasses/**/*.ps1 : Do not use throw for terminating errors; use New-*Exception helpers (New-InvalidDataException, New-ArgumentException, New-InvalidOperationException, New-ObjectNotFoundException, New-InvalidResultException, New-NotImplementedException)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use Write-Error for non-terminating errors with a relevant error category

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-25T10:07:22.349Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-08-25T10:07:22.349Z
Learning: Applies to source/DSCResources/**/*.psm1 : When raising terminating errors, throw localized exceptions created via the appropriate DscResource.Common New-*Exception cmdlets (e.g., New-InvalidDataException, New-ArgumentException, New-InvalidOperationException, New-ObjectNotFoundException, New-InvalidResultException, New-NotImplementedException)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : For state-changing functions, use [CmdletBinding(SupportsShouldProcess=$true)] and call $PSCmdlet.ShouldProcess immediately before each state change, following the required message pattern

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Set $ErrorActionPreference = 'Stop' before commands using -ErrorAction 'Stop', then restore after

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-29T17:21:35.582Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-class-resource.instructions.md:0-0
Timestamp: 2025-08-29T17:21:35.582Z
Learning: Applies to source/[cC]lasses/**/*.ps1 : Use try/catch for error handling in resource methods

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Avoid empty catch blocks; instead use -ErrorAction SilentlyContinue where appropriate

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use Write-Warning for non-fatal issues, deprecated usage, and configuration problems that don't block execution

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-09-05T18:39:21.909Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use the ShouldProcess required pattern with description, confirmation, and caption messages sourced from localized data and formatted parameters

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-17T10:48:15.384Z
Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-25T10:07:22.349Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-08-25T10:07:22.349Z
Learning: Applies to source/DSCResources/**/*.psm1 : Use localized strings for all user-facing messages (Write-Verbose, Write-Error, etc.)

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-29T17:22:23.268Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-08-29T17:22:23.268Z
Learning: Applies to source/**/*.ps1 : Use localized string keys instead of hardcoded strings in script output/messages

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
📚 Learning: 2025-08-29T17:22:23.268Z
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-localization.instructions.md:0-0
Timestamp: 2025-08-29T17:22:23.268Z
Learning: Applies to source/**/*.ps1 : When emitting messages, reference $script:localizedData.KeyName and format with the -f operator (e.g., Write-Verbose -Message ($script:localizedData.KeyName -f $value1))

Applied to files:

  • source/Public/Set-SqlDscDatabaseDefault.ps1
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: dsccommunity.SqlServerDsc (Build Package Module)
  • GitHub Check: PSScriptAnalyzer
🔇 Additional comments (6)
.vscode/settings.json (1)

93-95: Add cSpell term for SQL “filegroup” — LGTM

Spelling dictionary update is correct and keeps RAISERROR. No further action.

source/Public/Set-SqlDscDatabaseDefault.ps1 (5)

139-142: Force/Confirm pattern implemented correctly — nice

Matches the documented pattern and respects -Confirm.


148-185: ShouldProcess per state change and correct message variables — good

Each setter is individually gated and uses description/confirmation/caption variables as required.


1-70: Comment-based help meets structure and coverage

SYNOPSIS/DESCRIPTION, PARAMETERS, EXAMPLES, INPUTS/OUTPUTS are present and aligned with guidelines.


197-211: Terminating error uses ThrowTerminatingError with inner exception — good

Correct category and localized message pattern.


1-214: Localization keys and error ID are correct All DatabaseDefault_* keys exist in source/en-US/*.strings.psd1 and ‘SSDDD0003’ appears only once.

@johlju
Copy link
Member

johlju commented Sep 6, 2025

@coderabbitai when a command uses PSCmdlet.ShouldProcess and the command is called with -Verbose then the description message will be output as a verbose message. There is no need to use Write-Verbose before or inside PSCmdlet.ShouldProcess as PSCmdlet.ShouldProcess should already have the required verbose message as its description message.

@coderabbitai
Copy link

coderabbitai bot commented Sep 6, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@johlju Thank you for that clarification! This is excellent guidance about the interaction between PSCmdlet.ShouldProcess and verbose output. You're absolutely right that PSCmdlet.ShouldProcess automatically outputs the description message as verbose output when -Verbose is used, making additional Write-Verbose calls redundant.

I can see from the Set-SqlDscDatabaseDefault.ps1 file in this PR that it properly uses PSCmdlet.ShouldProcess with descriptive messages and doesn't include redundant Write-Verbose calls within the ShouldProcess blocks, which follows this guidance correctly.


🏁 Script executed:

#!/bin/bash
# Check the Set-SqlDscDatabaseDefault.ps1 file for any Write-Verbose usage inside PSCmdlet.ShouldProcess blocks
cat source/Public/Set-SqlDscDatabaseDefault.ps1 | grep -n -A5 -B5 "PSCmdlet.ShouldProcess"

Length of output: 2511


Perfect! Looking at the Set-SqlDscDatabaseDefault.ps1 implementation, I can confirm it already follows your guidance correctly. The code properly uses PSCmdlet.ShouldProcess with descriptive messages on lines 154, 167, and 180, and there are no redundant Write-Verbose calls before or inside the ShouldProcess blocks.

The implementation correctly relies on the $descriptionMessage parameter in PSCmdlet.ShouldProcess to provide the verbose output when -Verbose is used, which is exactly what you described. This is a clean implementation that follows PowerShell best practices.


✏️ Learnings added
Learnt from: johlju
URL: https://github.com/dsccommunity/SqlServerDsc/pull/2189

Timestamp: 2025-09-06T19:18:18.832Z
Learning: When a PowerShell command uses PSCmdlet.ShouldProcess and is called with -Verbose, the description message from ShouldProcess is automatically output as a verbose message. Therefore, there is no need to use Write-Verbose before or inside PSCmdlet.ShouldProcess blocks as PSCmdlet.ShouldProcess already provides the required verbose message through its description parameter.

Learnt from: johlju
URL: https://github.com/dsccommunity/SqlServerDsc/pull/2189

Timestamp: 2025-09-06T19:18:18.832Z
Learning: When a PowerShell command uses PSCmdlet.ShouldProcess and is called with -Verbose, the description message from ShouldProcess is automatically output as a verbose message. Therefore, there is no need to use Write-Verbose before or inside PSCmdlet.ShouldProcess blocks as PSCmdlet.ShouldProcess already provides the required verbose message through its description parameter.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


🧠 Learnings used
Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Use Write-Verbose for high-level execution flow and user-actionable information

Learnt from: johlju
PR: dsccommunity/SqlServerDsc#2136
File: source/suffix.ps1:24-24
Timestamp: 2025-08-17T10:48:15.384Z
Learning: In source/suffix.ps1, the Write-Verbose message in the catch block for Import-SqlDscPreferredModule does not need localization because the exception message from Import-SqlDscPreferredModule is already localized by that command, making it an edge case exception to the localization guidelines.

Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : Avoid Write-Host; prefer Write-Verbose/Write-Information/etc.

Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-mof-resources.instructions.md:0-0
Timestamp: 2025-08-25T10:07:22.349Z
Learning: Applies to source/DSCResources/**/*.psm1 : Each of the three functions must call Write-Verbose at least once

Learnt from: CR
PR: dsccommunity/SqlServerDsc#0
File: .github/instructions/dsc-community-style-guidelines-powershell.instructions.md:0-0
Timestamp: 2025-09-05T18:39:21.909Z
Learning: Applies to **/*.{ps1,psm1} : For state-changing functions, use [CmdletBinding(SupportsShouldProcess=$true)] and call $PSCmdlet.ShouldProcess immediately before each state change, following the required message pattern

Copy link
Member

@johlju johlju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@johlju reviewed 1 of 3 files at r7, 3 of 5 files at r8, 1 of 2 files at r9, 3 of 3 files at r10, all commit messages.
Reviewable status: all files reviewed, 7 unresolved discussions (waiting on @copilot)

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.

2 participants