Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
cd004e1
Initial plan
Copilot Nov 1, 2025
9bf8d27
Add New-SqlDscDatabaseSnapshot command with tests
Copilot Nov 1, 2025
b4e92fd
Update CHANGELOG to remove placeholder issue reference
Copilot Nov 1, 2025
b0b1ad5
Add integration tests for New-SqlDscFileGroup and New-SqlDscDataFile …
johlju Nov 1, 2025
18364c1
Add Add-SqlDscDataFile command with integration and unit tests
johlju Nov 1, 2025
d5a571d
Add FileGroup and DataFile classes with collections to manage databas…
johlju Nov 1, 2025
58d605d
Add Add-SqlDscFileGroup command and associated tests for managing Fil…
johlju Nov 1, 2025
964ff64
Add New-SqlDscDataFile command and associated tests for creating Data…
johlju Nov 1, 2025
2348266
Add New-SqlDscFileGroup command and associated tests for creating Fil…
johlju Nov 1, 2025
ba30af5
Enhance New-SqlDscDatabaseSnapshot and related commands to support Fi…
johlju Nov 1, 2025
c0d43ba
Add Force parameter to New-SqlDscDataFile and New-SqlDscFileGroup for…
johlju Nov 1, 2025
4be93c8
Fix OutputType attribute placement in New-SqlDscDataFile and New-SqlD…
johlju Nov 1, 2025
ce38251
Add tests for validating comment-based help structure and check for i…
johlju Nov 1, 2025
0e68808
Add suppression for ScriptAnalyzer warning in Add-SqlDscDataFile func…
johlju Nov 1, 2025
7fa7591
Add suppression for ScriptAnalyzer warning in Add-SqlDscFileGroup fun…
johlju Nov 1, 2025
6d242ec
Add validation for Database object in New-SqlDscFileGroup function; t…
johlju Nov 2, 2025
540de47
Add mock setup for Database object in New-SqlDscFileGroup integration…
johlju Nov 2, 2025
ea2b8b8
Refactor New-SqlDscDataFile function to simplify parameter handling a…
johlju Nov 2, 2025
8cdb4ee
Enhance integration tests for Add-SqlDscDataFile and Add-SqlDscFileGr…
johlju Nov 2, 2025
43d128f
Update CHANGELOG to reflect mandatory FileGroup parameter in New-SqlD…
johlju Nov 2, 2025
2658deb
Update CHANGELOG and documentation for Add-SqlDscDataFile to support …
johlju Nov 2, 2025
f14707a
Refactor New-SqlDscFileGroup integration tests to create a real SMO D…
johlju Nov 2, 2025
0877d60
Refactor integration tests for Add-SqlDscDataFile and Add-SqlDscFileG…
johlju Nov 2, 2025
ada3a7b
Add FileGroup parameter to New-SqlDscDatabase for custom file configu…
johlju Nov 2, 2025
64e77ad
Remove Add-SqlDscDataFile function and its associated tests; deprecat…
johlju Nov 2, 2025
a904aaf
Enhance New-SqlDscDataFile to automatically add DataFile to FileGroup…
johlju Nov 2, 2025
a53f0c6
Refactor New-SqlDscDataFile integration tests to validate FileGroup f…
johlju Nov 2, 2025
d15f4e7
Remove deprecated Add-SqlDscDataFile integration test from pipeline c…
johlju Nov 2, 2025
9030783
Refactor Add-SqlDscFileGroup integration tests to automatically creat…
johlju Nov 2, 2025
d410342
Remove `Add-SqlDscDataFile` command from changelog; deprecated functi…
johlju Nov 2, 2025
2b13c4e
Add integration tests for creating a database with custom file groups…
johlju Nov 2, 2025
0fdef27
Refactor example in New-SqlDscDatabase to use New-SqlDscFileGroup and…
johlju Nov 2, 2025
2abd5ef
Refactor New-SqlDscDataFile function to streamline process handling a…
johlju Nov 2, 2025
0b2442f
Merge branch 'main' into copilot/add-new-sqldscdatabase-snapshot
johlju Nov 2, 2025
6dcd22e
Refactor New-SqlDscDataFile integration tests to use BeforeEach for s…
johlju Nov 2, 2025
b0751ce
Add terminal profile settings for Copilot in VSCode configuration
johlju Nov 22, 2025
c7df494
Add unit tests for DatabaseFileSpec and conversion functions
johlju Nov 22, 2025
ff88554
Add new commands and PowerShell classes for database file and file gr…
johlju Nov 22, 2025
71d9956
Add file organization guidelines for classes and enums
johlju Nov 22, 2025
0fcf82b
Add suppression message for ScriptAnalyzer rule in New-SqlDscFileGrou…
johlju Nov 22, 2025
9de8739
Merge branch 'main' into copilot/add-new-sqldscdatabase-snapshot
johlju Nov 22, 2025
720aea3
Add new commands and integration tests for converting DatabaseFileSpe…
johlju Nov 22, 2025
5eace92
Add parameters for Size, MaxSize, Growth, GrowthType, and IsPrimaryFi…
johlju Nov 22, 2025
3b361a8
Fix formatting in ConvertTo-SqlDscFileGroup integration tests
johlju Nov 22, 2025
062bdff
Remove pipeline acceptance test for Database parameter in New-SqlDscF…
johlju Nov 22, 2025
3dbc133
Refactor ConvertTo-SqlDscDataFile and ConvertTo-SqlDscFileGroup integ…
johlju Nov 22, 2025
9ccc5df
Update parameter descriptions and usage for IsPrimaryFile in New-SqlD…
johlju Nov 22, 2025
103a80b
Fix IsDefault parameter usage in New-SqlDscFileGroup calls in databas…
johlju Nov 22, 2025
80abe5c
Add FileGroup parameter to New-SqlDscDatabaseSnapshot and update tests
johlju Nov 22, 2025
8cc7a16
Add New-SqlDscDatabaseSnapshot integration tests to pipeline
johlju Nov 22, 2025
714ec41
Remove test for Database parameter pipeline acceptance in New-SqlDscF…
johlju Nov 22, 2025
30293f3
Add -Confirm:$false parameter to Add-SqlDscFileGroup to suppress conf…
johlju Nov 22, 2025
5006eae
Remove test for Database parameter pipeline input acceptance in New-S…
johlju Nov 22, 2025
3a461fe
Refactor tests in ConvertTo-SqlDscDataFile and ConvertTo-SqlDscFileGr…
johlju Nov 22, 2025
434b68c
Remove unused mockComputerName variable and enhance snapshot file cre…
johlju Nov 22, 2025
d8e8d41
Add guideline to avoid using param() inside -MockWith scriptblocks
johlju Nov 22, 2025
0078099
Add Force parameter to Add-SqlDscFileGroup and update related strings…
johlju Nov 22, 2025
512a16f
Enhance documentation for ConvertTo-SqlDscDataFile by adding INPUTS s…
johlju Nov 22, 2025
8be826e
Add Force parameter to New-SqlDscDataFile tests to bypass confirmatio…
johlju Nov 22, 2025
d1ffdc0
Add INPUTS section to Add-SqlDscFileGroup documentation for clarity
johlju Nov 22, 2025
24ec742
Refactor New-SqlDscDatabaseSnapshot test to improve mock DatabaseFile…
johlju Nov 22, 2025
72431a7
Add ErrorAction 'Stop' to Add-SqlDscFileGroup tests for improved erro…
johlju Nov 22, 2025
8885a76
Refactor New-SqlDscDataFile tests to streamline assertions and improv…
johlju Nov 22, 2025
0cabd5f
Remove verbose message for file group creation in New-SqlDscFileGroup…
johlju Nov 22, 2025
20cf372
Enhance documentation for New-SqlDscDataFile parameters and outputs, …
johlju Nov 22, 2025
c0b239e
Remove PassThru parameter from New-SqlDscFileGroup function to stream…
johlju Nov 22, 2025
0d77081
Enhance DatabaseFileGroupSpec tests to verify instance creation with …
johlju Nov 22, 2025
fc78845
Refactor BeforeAll and AfterAll blocks to streamline module import an…
johlju Nov 22, 2025
a64e736
Refactor DatabaseFileSpec tests to simplify instantiation checks by r…
johlju Nov 22, 2025
2bd3c56
Fix comments and error messages in Add-SqlDscFileGroup tests for clarity
johlju Nov 22, 2025
349b328
Refactor New-SqlDscFileGroup tests to eliminate InModuleScope usage f…
johlju Nov 22, 2025
60bfadb
Add parameter set validation test for ConvertTo-SqlDscFileGroup command
johlju Nov 22, 2025
12f1994
Refactor terminal profile settings in VSCode configuration for clarity
johlju Nov 22, 2025
2737346
Update output documentation for cmdlets to clarify return types and c…
johlju Nov 22, 2025
973dc55
Refactor DatabaseFileGroupSpec tests to improve variable scoping and …
johlju Nov 22, 2025
1bcc175
Add input documentation and validation for DataFileSpec parameter in …
johlju Nov 22, 2025
123856e
Return FileGroup object when PassThru parameter is specified in Add-S…
johlju Nov 22, 2025
43fdbc5
Update New-SqlDscFileGroup to set 'Standalone' as the default paramet…
johlju Nov 22, 2025
ae8a1b6
Add input documentation for New-SqlDscFileGroup and update FileGroupS…
johlju Nov 22, 2025
3127195
Add tests for New-SqlDscFileGroup to validate FileGroupSpec creation …
johlju Nov 22, 2025
93f434e
Return FileGroup object when PassThru parameter is specified in Add-S…
johlju Nov 22, 2025
c6ac9a0
Refactor variable names for consistency in New-SqlDscDataFile.Tests.ps1
johlju Nov 22, 2025
bcaa6fa
Add automatic file group generation in New-SqlDscDatabaseSnapshot whe…
johlju Nov 23, 2025
3dea101
Refactor New-SqlDscDatabaseSnapshot to use New-SqlDscDataFile and New…
johlju Nov 23, 2025
3cf2e5a
Refactor New-SqlDscDatabaseSnapshot.Tests.ps1 to use platform-specifi…
johlju Nov 23, 2025
4a4b5d6
Add cleanup logic for existing snapshots in New-SqlDscDatabaseSnapsho…
johlju Nov 23, 2025
87353f5
Move verbose logging for database snapshot creation to the end of the…
johlju Nov 24, 2025
4b60a75
Add cleanup logic for database snapshots in AfterEach blocks of integ…
johlju Nov 24, 2025
baafa8d
Enhance documentation for New-SqlDscDatabaseSnapshot cmdlet to clarif…
johlju Nov 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ applyTo: "**/*.[Tt]ests.ps1"
- Mock variables prefix: 'mock'

## Structure & Scope
- Public commands: Never use `InModuleScope` (unless retrieving localized strings)
- Public commands: Never use `InModuleScope` (unless retrieving localized strings or creating an object using an internal class)
- Private functions/class resources: Always use `InModuleScope`
- Each class method = separate `Context` block
- Each scenario = separate `Context` block
Expand All @@ -46,6 +46,7 @@ applyTo: "**/*.[Tt]ests.ps1"
- Set `$PSDefaultParameterValues` for `Mock:ModuleName`, `Should:ModuleName`, `InModuleScope:ModuleName`
- Omit `-ModuleName` parameter on Pester commands
- Never use `Mock` inside `InModuleScope`-block
- Never use `param()` inside `-MockWith` scriptblocks, parameters are auto-bound

## File Organization
- Class resources: `tests/Unit/Classes/{Name}.Tests.ps1`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ applyTo: "**"
## File Organization
- Public commands: `source/Public/{CommandName}.ps1`
- Private functions: `source/Private/{FunctionName}.ps1`
- Classes: `source/Classes/{DependencyGroupNumber}.{ClassName}.ps1`
- Enums: `source/Enum/{DependencyGroupNumber}.{EnumName}.ps1`
- Unit tests: `tests/Unit/{Classes|Public|Private}/{Name}.Tests.ps1`
- Integration tests: `tests/Integration/Commands/{CommandName}.Integration.Tests.ps1`

Expand Down
21 changes: 21 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,26 @@
"path": "bash",
"args": []
}
},
"chat.tools.terminal.terminalProfile.osx": {
"path": "pwsh",
"args": [],
"env": {
"COPILOT": "1"
}
},
"chat.tools.terminal.terminalProfile.linux": {
"path": "pwsh",
"args": [],
"env": {
"COPILOT": "1"
}
},
"chat.tools.terminal.terminalProfile.windows": {
"path": "pwsh.exe",
"args": [],
"env": {
"COPILOT": "1"
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,39 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added public command `New-SqlDscDatabaseSnapshot` to create database snapshots
in a SQL Server Database Engine instance using SMO. This command provides an
automated and DSC-friendly approach to snapshot management by leveraging
`New-SqlDscDatabase` for the actual creation. The command now supports `FileGroup`
and `DataFile` parameters to allow control over snapshot file placement and
structure ([issue #2341](https://github.com/dsccommunity/SqlServerDsc/issues/2341)).
- Added public command `New-SqlDscFileGroup` to create FileGroup objects for SQL
Server databases. This command simplifies creating FileGroup objects that can be
used with `New-SqlDscDatabase` and other database-related commands. The `Database`
parameter is optional, allowing FileGroup objects to be created standalone and
added to a Database later using `Add-SqlDscFileGroup`.
- Added public command `New-SqlDscDataFile` to create DataFile objects for SQL
Server FileGroups. This command simplifies creating DataFile objects with
specified physical file paths, supporting both regular database files (.mdf, .ndf)
and sparse files for database snapshots (.ss). The `FileGroup` parameter is
mandatory, requiring DataFile objects to be created with an associated FileGroup.
- Added public command `Add-SqlDscFileGroup` to add one or more FileGroup objects
to a Database. This command provides a clean way to associate FileGroup objects
with a Database after they have been created.
- Added public command `ConvertTo-SqlDscDataFile` to convert `DatabaseFileSpec`
objects to SMO DataFile objects.
- Added public command `ConvertTo-SqlDscFileGroup` to convert `DatabaseFileGroupSpec`
objects to SMO FileGroup objects.
- Added class `DatabaseFileSpec` to define data file specifications without requiring
a database or SMO context.
- Added class `DatabaseFileGroupSpec` to define file group specifications with
associated data files without requiring a database or SMO context.
- `New-SqlDscDatabase`
- Added `FileGroup` and `DataFile` parameters to allow specifying custom file
locations and structure. These parameters apply to both regular databases and
database snapshots, enabling control over file placement for snapshots (sparse
files) and custom filegroup/datafile configuration for regular databases
([issue #2341](https://github.com/dsccommunity/SqlServerDsc/issues/2341)).
- Added public command `Set-SqlDscDatabaseOwner` to change the owner of a SQL Server
database [issue #2177](https://github.com/dsccommunity/SqlServerDsc/issues/2177).
This command uses the SMO `SetOwner()` method and supports both `ServerObject`
Expand Down
6 changes: 6 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ stages:
# Group 2
'tests/Integration/Commands/PostInstallationConfiguration.Integration.Tests.ps1'
# Group 3
'tests/Integration/Commands/New-SqlDscFileGroup.Integration.Tests.ps1'
'tests/Integration/Commands/New-SqlDscDataFile.Integration.Tests.ps1'
'tests/Integration/Commands/Add-SqlDscFileGroup.Integration.Tests.ps1'
'tests/Integration/Commands/ConvertTo-SqlDscFileGroup.Integration.Tests.ps1'
'tests/Integration/Commands/ConvertTo-SqlDscDataFile.Integration.Tests.ps1'
'tests/Integration/Commands/Get-SqlDscSetupLog.Integration.Tests.ps1'
'tests/Integration/Commands/Connect-SqlDscDatabaseEngine.Integration.Tests.ps1'
'tests/Integration/Commands/Disconnect-SqlDscDatabaseEngine.Integration.Tests.ps1'
Expand Down Expand Up @@ -335,6 +340,7 @@ stages:
'tests/Integration/Commands/Get-SqlDscDatabase.Integration.Tests.ps1'
'tests/Integration/Commands/ConvertFrom-SqlDscDatabasePermission.Integration.Tests.ps1'
'tests/Integration/Commands/New-SqlDscDatabase.Integration.Tests.ps1'
'tests/Integration/Commands/New-SqlDscDatabaseSnapshot.Integration.Tests.ps1'
'tests/Integration/Commands/Get-SqlDscCompatibilityLevel.Integration.Tests.ps1'
'tests/Integration/Commands/Set-SqlDscDatabaseProperty.Integration.Tests.ps1'
'tests/Integration/Commands/Set-SqlDscDatabaseOwner.Integration.Tests.ps1'
Expand Down
97 changes: 97 additions & 0 deletions source/Classes/002.DatabaseFileSpec.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<#
.SYNOPSIS
Defines a data file specification for a database file group.

.DESCRIPTION
This class represents a data file specification that can be used when
creating a new database. It contains the properties needed to define
a data file without requiring an existing database or file group SMO object.

.PARAMETER Name
The logical name of the data file.

.PARAMETER FileName
The physical file path for the data file. This must be a valid path
on the SQL Server instance.

.PARAMETER Size
The initial size of the data file in kilobytes. If not specified,
SQL Server will use its default initial size.

.PARAMETER MaxSize
The maximum size to which the data file can grow in kilobytes.
If not specified, the file can grow without limit (or up to disk space).

.PARAMETER Growth
The amount by which the data file grows when it needs more space.
The value is in kilobytes if GrowthType is KB, or a percentage if
GrowthType is Percent. If not specified, SQL Server will use its
default growth setting.

.PARAMETER GrowthType
Specifies whether the Growth value is in kilobytes (KB) or percent (Percent).
If not specified, defaults to KB.

.PARAMETER IsPrimaryFile
Specifies that this file is the primary file in the PRIMARY file group.
Only one file in the PRIMARY file group should be marked as the primary file.
This property is typically used for the first file in the PRIMARY file group.

.NOTES
This class is used to specify data file configurations when creating a new
database via New-SqlDscDatabase. Unlike SMO DataFile objects, these
specification objects can be created without an existing database context.

Comment thread
coderabbitai[bot] marked this conversation as resolved.
.EXAMPLE
$fileSpec = [DatabaseFileSpec]::new()
$fileSpec.Name = 'MyDatabase_Data'
$fileSpec.FileName = 'C:\SQLData\MyDatabase.mdf'
$fileSpec.Size = 102400 # 100 MB in KB
$fileSpec.Growth = 10240 # 10 MB in KB
$fileSpec.GrowthType = 'KB'

Creates a new data file specification with a specific size and growth settings.

.EXAMPLE
[DatabaseFileSpec] @{
Name = 'MyDatabase_Data'
FileName = 'C:\SQLData\MyDatabase.mdf'
IsPrimaryFile = $true
}

Creates a new primary data file specification using hashtable syntax.
#>
class DatabaseFileSpec
{
[System.String]
$Name

[System.String]
$FileName

[System.Nullable[System.Double]]
$Size

[System.Nullable[System.Double]]
$MaxSize

[System.Nullable[System.Double]]
$Growth

[ValidateSet('KB', 'MB', 'Percent')]
[System.String]
$GrowthType

[System.Boolean]
$IsPrimaryFile = $false

DatabaseFileSpec()
{
}

DatabaseFileSpec([System.String] $name, [System.String] $fileName)
{
$this.Name = $name
$this.FileName = $fileName
}
}
110 changes: 110 additions & 0 deletions source/Classes/004.DatabaseFileGroupSpec.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<#
.SYNOPSIS
Defines a file group specification for a database.

.DESCRIPTION
This class represents a file group specification that can be used when
creating a new database. It contains the properties needed to define
a file group and its associated data files without requiring an existing
database SMO object.

.PARAMETER Name
The name of the file group. For the primary file group, this should be 'PRIMARY'.

.PARAMETER Files
An array of DatabaseFileSpec objects that define the data files belonging
to this file group. At least one file must be specified for each file group.

.PARAMETER ReadOnly
Specifies whether the file group is read-only. If not specified, defaults
to $false (read-write).

.PARAMETER IsDefault
Specifies whether this file group should be the default file group for
new objects. If not specified, defaults to $false. Typically, only the
PRIMARY file group or one custom file group should be marked as default.

.NOTES
This class is used to specify file group configurations when creating a new
database via New-SqlDscDatabase. Unlike SMO FileGroup objects, these
specification objects can be created without an existing database context.

When creating a database, you typically need at least one file group named
'PRIMARY' which contains the primary data file. Additional file groups can
be added for organizing data files.
Comment thread
johlju marked this conversation as resolved.

.EXAMPLE
$primaryFile = [DatabaseFileSpec] @{
Name = 'MyDatabase_Primary'
FileName = 'C:\SQLData\MyDatabase.mdf'
IsPrimaryFile = $true
}

$primaryFileGroup = [DatabaseFileGroupSpec]::new()
$primaryFileGroup.Name = 'PRIMARY'
$primaryFileGroup.Files = @($primaryFile)

Creates a PRIMARY file group specification with one primary data file.

.EXAMPLE
$dataFile1 = [DatabaseFileSpec] @{
Name = 'MyDatabase_Data1'
FileName = 'D:\SQLData\MyDatabase_Data1.ndf'
Size = 204800 # 200 MB
}

$dataFile2 = [DatabaseFileSpec] @{
Name = 'MyDatabase_Data2'
FileName = 'D:\SQLData\MyDatabase_Data2.ndf'
Size = 204800 # 200 MB
}

$secondaryFileGroup = [DatabaseFileGroupSpec] @{
Name = 'SECONDARY'
Files = @($dataFile1, $dataFile2)
}

Creates a SECONDARY file group specification with two data files.

.EXAMPLE
[DatabaseFileGroupSpec] @{
Name = 'PRIMARY'
Files = @(
[DatabaseFileSpec] @{
Name = 'MyDB_Primary'
FileName = 'C:\SQLData\MyDB.mdf'
}
)
}

Creates a PRIMARY file group using hashtable syntax with an embedded file spec.
#>
class DatabaseFileGroupSpec
{
[System.String]
$Name

[DatabaseFileSpec[]]
$Files

[System.Boolean]
$ReadOnly = $false

[System.Boolean]
$IsDefault = $false

DatabaseFileGroupSpec()
{
}

DatabaseFileGroupSpec([System.String] $name)
{
$this.Name = $name
}

DatabaseFileGroupSpec([System.String] $name, [DatabaseFileSpec[]] $files)
{
$this.Name = $name
$this.Files = $files
}
}
Loading
Loading