Skip to content

Commit b6ddc10

Browse files
authored
SqlDatabase: Refactored class-bases resource (#2384)
1 parent 5c65e63 commit b6ddc10

File tree

15 files changed

+2379
-1668
lines changed

15 files changed

+2379
-1668
lines changed

.github/instructions/SqlServerDsc-guidelines.instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ applyTo: "**"
2020

2121
## Resources
2222
- Database Engine resources: inherit `SqlResourceBase`
23-
- Add `InstanceName`, `ServerName`, and `Credential` to `$this.ExcludeDscProperties`
24-
- `SqlResourceBase` provides: `InstanceName`, `ServerName`, `Credential`, `Reasons`, `GetServerObject()`
23+
- Add any DSC properties whose values cannot be enforced as desired state to `$this.ExcludeDscProperties`
24+
- `SqlResourceBase` provides: `InstanceName`, `ServerName`, `Port`, `Protocol`, `Credential`, `Reasons`, `GetServerObject()`
2525
- Constructor: `MyResourceName() : base () { }` (no $PSScriptRoot parameter)
2626

2727
## SQL Server Interaction

CHANGELOG.md

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2727
- Added `Protocol` parameter to specify the network protocol when connecting.
2828
- Added `Port` parameter to specify the TCP port number when connecting.
2929
Connection strings now support the format `[protocol:]hostname[\instance][,port]`.
30+
- `SqlDatabase`
31+
- Added new class-based resource to create, modify, or remove databases on a
32+
SQL Server instance. Supports a comprehensive set of database properties
33+
that can be configured with `Set-SqlDscDatabaseProperty`
34+
([issue #2174](https://github.com/dsccommunity/SqlServerDsc/issues/2174)).
3035
- `Install-SqlDscServer`
3136
- Added parameter `AllowDqRemoval` to the `Upgrade` parameter set
3237
([issue #2155](https://github.com/dsccommunity/SqlServerDsc/issues/2155)).
@@ -91,6 +96,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9196
later versions.
9297
- Now outputs setup progress when `-Verbose` is passed by using `/QUIETSIMPLE`
9398
instead of `/QUIET`.
99+
- `SqlResourceBase`
100+
- Added the method `ConvertToSmoEnumType()` to convert string values to SMO
101+
enum types at runtime. This method can be used by all resources inheriting
102+
from `SqlResourceBase` and supports a default namespace parameter to avoid
103+
repeating the full type name
104+
([issue #2174](https://github.com/dsccommunity/SqlServerDsc/issues/2174)).
94105

95106
### Changed
96107

@@ -127,8 +138,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
127138
([issue #2376](https://github.com/dsccommunity/SqlServerDsc/issues/2376)).
128139
- `SqlRS`
129140
- Fixed integration tests failing with status code 0 when checking ReportServer
130-
and Reports site accessibility by implementing retry logic (up to 2 minutes) to
131-
handle timing issues where Reporting Services web services are not immediately
141+
and Reports site accessibility by implementing retry logic (up to 2 minutes)
142+
to handle timing issues where Reporting Services web services are not immediately
132143
ready after DSC configuration completes. On final retry attempt with status
133144
code 0, the exception is now re-thrown to provide detailed error diagnostics
134145
([issue #2376](https://github.com/dsccommunity/SqlServerDsc/issues/2376)).
@@ -182,9 +193,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
182193
`System.Boolean` to `Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff`
183194
to match SMO property types and support all valid values (Off, On, Primary)
184195
([issue #2190](https://github.com/dsccommunity/SqlServerDsc/issues/2190)).
185-
- Fixed parameter types for boolean database properties from `System.Boolean` to
186-
`System.Management.Automation.SwitchParameter` to follow PowerShell best practices.
187-
([issue #2190](https://github.com/dsccommunity/SqlServerDsc/issues/2190)).
196+
- Fixed parameter types for boolean database properties from `System.Boolean`
197+
to `System.Management.Automation.SwitchParameter` to follow PowerShell best
198+
practices ([issue #2190](https://github.com/dsccommunity/SqlServerDsc/issues/2190)).
188199
- `New-SqlDscRole`
189200
- Fixed duplicate verbose output by removing manual `Write-Verbose` call, as
190201
`$PSCmdlet.ShouldProcess()` already generates appropriate verbose output
@@ -194,12 +205,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
194205
`System.Boolean` to `Microsoft.SqlServer.Management.Smo.DatabaseScopedConfigurationOnOff`
195206
to match SMO property types and support all valid values (Off, On, Primary)
196207
([issue #2190](https://github.com/dsccommunity/SqlServerDsc/issues/2190)).
197-
- Fixed parameter types for boolean database properties from `System.Boolean` to
198-
`System.Management.Automation.SwitchParameter` to follow PowerShell best practices.
199-
([issue #2190](https://github.com/dsccommunity/SqlServerDsc/issues/2190)).
208+
- Fixed parameter types for boolean database properties from `System.Boolean`
209+
to `System.Management.Automation.SwitchParameter` to follow PowerShell best
210+
practices ([issue #2190](https://github.com/dsccommunity/SqlServerDsc/issues/2190)).
200211

201212
### Removed
202213

214+
- `DSC_SqlDatabase`
215+
- Removed the legacy MOF-based resource. Use the new class-based `SqlDatabase`
216+
resource instead
217+
([issue #2174](https://github.com/dsccommunity/SqlServerDsc/issues/2174)).
203218
- Removed helper function `Get-FilePathMajorVersion` from the SqlServerDsc.Common
204219
module. Refactored usages to use the command `Get-FileVersion` from the
205220
DscResource.Common module instead
@@ -225,8 +240,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
225240
Use the new command `Set-SqlDscDatabaseOwner` to change database ownership instead.
226241
- BREAKING CHANGE: `Set-SqlDscDatabaseProperty`
227242
- Removed parameters `AzureEdition` and `AzureServiceObjective`. Azure SQL Database
228-
service tier and SLO changes should be managed using `Set-AzSqlDatabase` from the
229-
Azure PowerShell module instead. See [issue #2177](https://github.com/dsccommunity/SqlServerDsc/issues/2177).
243+
service tier and SLO changes should be managed using `Set-AzSqlDatabase`
244+
from the Azure PowerShell module instead. See [issue #2177](https://github.com/dsccommunity/SqlServerDsc/issues/2177).
230245
- Removed parameter `DatabaseSnapshotBaseName`. Database snapshots should be
231246
created using the `New-SqlDscDatabaseSnapshot`, or the `New-SqlDscDatabase`
232247
command with the `-DatabaseSnapshotBaseName` parameter.
@@ -253,10 +268,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
253268
and `DataFile` parameters to allow control over snapshot file placement and
254269
structure ([issue #2341](https://github.com/dsccommunity/SqlServerDsc/issues/2341)).
255270
- Added public command `New-SqlDscFileGroup` to create FileGroup objects for SQL
256-
Server databases. This command simplifies creating FileGroup objects that can be
257-
used with `New-SqlDscDatabase` and other database-related commands. The `Database`
258-
parameter is optional, allowing FileGroup objects to be created standalone and
259-
added to a Database later using `Add-SqlDscFileGroup`.
271+
Server databases. This command simplifies creating FileGroup objects that
272+
can be used with `New-SqlDscDatabase` and other database-related commands.
273+
The `Database` parameter is optional, allowing FileGroup objects to be
274+
created standalone and added to a Database later using `Add-SqlDscFileGroup`.
260275
- Added public command `New-SqlDscDataFile` to create DataFile objects for SQL
261276
Server FileGroups. This command simplifies creating DataFile objects with
262277
specified physical file paths, supporting both regular database files (.mdf, .ndf)
@@ -279,9 +294,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
279294
database snapshots, enabling control over file placement for snapshots (sparse
280295
files) and custom filegroup/datafile configuration for regular databases
281296
([issue #2341](https://github.com/dsccommunity/SqlServerDsc/issues/2341)).
282-
- Added `IsLedger` parameter to support creating ledger databases at creation time.
283-
Ledger status is read-only after database creation and can only be set when
284-
creating a new database ([issue #2351](https://github.com/dsccommunity/SqlServerDsc/issues/2351)).
297+
- Added `IsLedger` parameter to support creating ledger databases at creation
298+
time. Ledger status is read-only after database creation and can only be set
299+
when creating a new database ([issue #2351](https://github.com/dsccommunity/SqlServerDsc/issues/2351)).
285300
- Added public command `Set-SqlDscDatabaseOwner` to change the owner of a SQL Server
286301
database [issue #2177](https://github.com/dsccommunity/SqlServerDsc/issues/2177).
287302
This command uses the SMO `SetOwner()` method and supports both `ServerObject`
@@ -300,8 +315,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
300315
to resolve Sysprep compatibility errors [issue #2212](https://github.com/dsccommunity/SqlServerDsc/issues/2212).
301316
- Added integration tests for `Complete-SqlDscImage` command to ensure command
302317
reliability in prepared image installation workflows. The test runs in a separate
303-
pipeline job `Integration_Test_Commands_SqlServer_PreparedImage` with its own CI
304-
worker, and verifies the completion of SQL Server instances prepared using
318+
pipeline job `Integration_Test_Commands_SqlServer_PreparedImage` with its own
319+
CI worker, and verifies the completion of SQL Server instances prepared using
305320
`Install-SqlDscServer` with the `-PrepareImage` parameter. The test includes
306321
scenarios with minimal parameters and various service account/directory
307322
configurations [issue #2212](https://github.com/dsccommunity/SqlServerDsc/issues/2212).
@@ -1411,7 +1426,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14111426
- Removed `Test-IsNumericType` from private functions ([issue #1795](https://github.com/dsccommunity/SqlServerDsc/issues/1795)).
14121427
- `Test-IsNumericType` added to _DscResource.Common_ public functions
14131428
([issue #87](https://github.com/dsccommunity/DscResource.Common/issues/87)).
1414-
- Removed `Test-ServiceAccountRequirePassword` from private functions ([issue #1794](https://github.com/dsccommunity/SqlServerDsc/issues/1794)
1429+
- Removed `Test-ServiceAccountRequirePassword` from private functions
1430+
([issue #1794](https://github.com/dsccommunity/SqlServerDsc/issues/1794)
14151431
- Replaced by `Test-AccountRequirePassword` that was added to _DscResource.Common_
14161432
public functions ([issue #93](https://github.com/dsccommunity/DscResource.Common/issues/93)).
14171433
- Removed `Assert-RequiredCommandParameter` from private functions ([issue #1796](https://github.com/dsccommunity/SqlServerDsc/issues/1796)).
@@ -1651,8 +1667,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
16511667
- The deprecated DSC resource SqlServerEndpointState have been removed _(and_
16521668
_replaced by a property in [**SqlEndpoint**](https://github.com/dsccommunity/SqlServerDsc/wiki/sqlendpoint))_
16531669
([issue #1725](https://github.com/dsccommunity/SqlServerDsc/issues/1725)).
1654-
- The deprecated DSC resource SqlServerNetwork have been removed _(and replaced by_
1655-
_[**SqlProtocol**](https://github.com/dsccommunity/SqlServerDsc/wiki/sqlprotocol)_
1670+
- The deprecated DSC resource SqlServerNetwork have been removed _(and replaced_
1671+
_by [**SqlProtocol**](https://github.com/dsccommunity/SqlServerDsc/wiki/sqlprotocol)_
16561672
_and [**SqlProtocolTcpIp**](https://github.com/dsccommunity/SqlServerDsc/wiki/sqlprotocoltcpip))_
16571673
([issue #1725](https://github.com/dsccommunity/SqlServerDsc/issues/1725)).
16581674
- CommonTestHelper
@@ -2627,8 +2643,8 @@ in a future release.
26272643
or `features`.
26282644
- Now code coverage is reported to Codecov, and a codecov.yml was added.
26292645
- Updated to support DscResource.Common v0.7.1.
2630-
- Changed to point to CONTRIBUTING.md on master branch to avoid "404 Page not found"
2631-
([issue #1508](https://github.com/dsccommunity/SqlServerDsc/issues/1508)).
2646+
- Changed to point to CONTRIBUTING.md on master branch to avoid
2647+
"404 Page not found" ([issue #1508](https://github.com/dsccommunity/SqlServerDsc/issues/1508)).
26322648
- SqlAGDatabase
26332649
- Fixed unit tests that failed intermittently when running unit tests
26342650
in PowerShell 7 ([issue #1532](https://github.com/dsccommunity/SqlServerDsc/issues/1532)).
@@ -3774,8 +3790,8 @@ in a future release.
37743790
- Changed the tests so that the local SqlInstall account is added as a member
37753791
of the local administrators group.
37763792
- Changed the tests so that the local SqlInstall account is added as a member
3777-
of the system administrators in SQL Server (Database Engine) - needed for the
3778-
xSQLServerAlwaysOnService integration tests.
3793+
of the system administrators in SQL Server (Database Engine) - needed for
3794+
the xSQLServerAlwaysOnService integration tests.
37793795
- Changed so that only one of the Modules-folder for the SQLPS PowerShell module
37803796
for SQL Server 2016 is renamed back so it can be used with the integration
37813797
tests. There was an issue when more than one SQLPS module was present (see
@@ -4238,7 +4254,8 @@ in a future release.
42384254
- Changes to xSQLServerSetup
42394255
- Added a note to the README.md saying that it is not possible to add or remove
42404256
features from a SQL Server failover cluster (issue #433).
4241-
- Changed so that it reports false if the desired state is not correct (issue #432).
4257+
- Changed so that it reports false if the desired state is not correct
4258+
(issue #432).
42424259
- Added a test to make sure we always return false if a SQL Server failover
42434260
cluster is missing features.
42444261
- Helper function Connect-SQLAnalysis

source/Classes/020.SqlAudit.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ class SqlAudit : SqlResourceBase
575575
# Remove properties that is not an audit property.
576576
'InstanceName'
577577
'ServerName'
578+
'Port'
579+
'Protocol'
578580
'Ensure'
579581
'Force'
580582
'Credential'

0 commit comments

Comments
 (0)