Skip to content

Commit f29221f

Browse files
committed
Refactor Set-SqlDscDatabase to remove deprecated parameters and update documentation for method calls
1 parent 806c6fc commit f29221f

File tree

3 files changed

+14
-46
lines changed

3 files changed

+14
-46
lines changed

CHANGELOG.md

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -229,30 +229,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
229229
### Changed
230230

231231
- `Set-SqlDscDatabase`
232-
- BREAKING CHANGE: Completely refactored to support all 85+ settable SMO Database
232+
- BREAKING CHANGE: Completely refactored to support settable SMO Database
233233
properties as parameters ([issue #2177](https://github.com/dsccommunity/SqlServerDsc/issues/2177)).
234-
The command now uses a generic property-setting loop instead of hard‑coded handling.
235-
Writable examples include:
236-
- 46 Boolean properties (e.g., `AnsiNullDefault`, `AutoClose`, `AutoShrink`,
237-
`RecursiveTriggersEnabled`, `QuotedIdentifiersEnabled`)
238-
- 8 Int32 properties (e.g., `TargetRecoveryTime`, `TwoDigitYearCutoff`, `MaxDop`)
239-
- 19 String properties (e.g., `Collation`, `DefaultSchema`)
240-
- 11 Enum properties (e.g., `CompatibilityLevel`, `PageVerify`, `RecoveryModel`,
241-
`UserAccess`)
242-
- Note: This command excludes properties that are only settable at database
243-
creation time (e.g., `CatalogCollation`, `ContainmentType`), properties
244-
requiring specific SMO methods instead of direct assignment (e.g., default
245-
filegroup changes via `SetDefaultFileGroup()`, snapshot isolation via
246-
`SetSnapshotIsolation()`, full‑text catalog management, FILESTREAM configuration),
247-
and properties managed by dedicated commands (e.g., database ownership via
248-
`Set-SqlDscDatabaseOwner`). Property availability may vary by SQL Server version;
249-
the command dynamically exposes properties supported by the current SMO version.
250-
- Removed all property-specific validation logic - SMO now handles validation
251-
- Removed individual property update messages - now uses generic
252-
`Database_UpdatingProperty` message
253-
- Added check to skip updating properties that are already set to the desired value
254-
- Properties are only modified if they differ from the current value, reducing
255-
unnecessary database operations
256234
- `Remove-SqlDscAgentAlert`
257235
- Now uses `$PSCmdlet.ThrowTerminatingError()` instead of exception helper
258236
functions for proper terminating error handling ([issue #2193](https://github.com/dsccommunity/SqlServerDsc/issues/2193)).

source/Public/Set-SqlDscDatabase.ps1

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,6 @@
116116
.PARAMETER DateCorrelationOptimization
117117
Specifies whether date correlation optimization is enabled to speed up temporal joins.
118118
119-
.PARAMETER DefaultFileGroup
120-
Specifies the name of the default filegroup for the database.
121-
122-
.PARAMETER DefaultFileStreamFileGroup
123-
Specifies the name of the default FILESTREAM filegroup.
124-
125119
.PARAMETER DefaultFullTextCatalog
126120
Specifies the default full-text catalog used for full-text indexes.
127121
@@ -242,9 +236,6 @@
242236
.PARAMETER RemoteDatabaseName
243237
Specifies the remote database name for remote data archive.
244238
245-
.PARAMETER SnapshotIsolationState
246-
Specifies whether SNAPSHOT isolation is OFF/ON/IN_TRANSITION.
247-
248239
.PARAMETER TargetRecoveryTime
249240
Specifies the target recovery time (seconds) for indirect checkpointing.
250241
@@ -311,6 +302,17 @@
311302
objects. This property is marked as ReadOnlyAfterCreation in the SMO Database
312303
class and can only be set during database creation (e.g., using New-SqlDscDatabase
313304
or CREATE DATABASE statements).
305+
306+
The following database properties require method calls instead of direct property
307+
assignment and will be supported through separate commands:
308+
309+
- **DefaultFileGroup**: The default filegroup for the database. Use the
310+
`SetDefaultFileGroup()` method via a dedicated command.
311+
- **DefaultFileStreamFileGroup**: The default FILESTREAM filegroup. Use the
312+
`SetDefaultFileStreamFileGroup()` method via a dedicated command.
313+
- **SnapshotIsolationState**: The snapshot isolation state (OFF/ON/IN_TRANSITION).
314+
Use the `SetSnapshotIsolation()` method via a dedicated command or ALTER DATABASE
315+
T-SQL statements.
314316
#>
315317
function Set-SqlDscDatabase
316318
{
@@ -555,14 +557,6 @@ function Set-SqlDscDatabase
555557
[System.String]
556558
$Collation,
557559

558-
[Parameter()]
559-
[System.String]
560-
$DefaultFileGroup,
561-
562-
[Parameter()]
563-
[System.String]
564-
$DefaultFileStreamFileGroup,
565-
566560
[Parameter()]
567561
[System.String]
568562
$DefaultFullTextCatalog,
@@ -644,10 +638,6 @@ function Set-SqlDscDatabase
644638
[Microsoft.SqlServer.Management.Smo.RecoveryModel]
645639
$RecoveryModel,
646640

647-
[Parameter()]
648-
[Microsoft.SqlServer.Management.Smo.SnapshotIsolationState]
649-
$SnapshotIsolationState,
650-
651641
[Parameter()]
652642
[Microsoft.SqlServer.Management.Smo.DatabaseUserAccess]
653643
$UserAccess,

tests/Unit/Public/Set-SqlDscDatabase.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ Describe 'Set-SqlDscDatabase' -Tag 'Public' {
317317
It 'Should have the correct parameters in parameter set ServerObjectSet' -ForEach @(
318318
@{
319319
ExpectedParameterSetName = 'ServerObjectSet'
320-
ExpectedParameters = '-ServerObject <Server> -Name <string> [-Refresh] [-AcceleratedRecoveryEnabled <bool>] [-AnsiNullDefault <bool>] [-AnsiNullsEnabled <bool>] [-AnsiPaddingEnabled <bool>] [-AnsiWarningsEnabled <bool>] [-ArithmeticAbortEnabled <bool>] [-AutoClose <bool>] [-AutoCreateIncrementalStatisticsEnabled <bool>] [-AutoCreateStatisticsEnabled <bool>] [-AutoShrink <bool>] [-AutoUpdateStatisticsAsync <bool>] [-AutoUpdateStatisticsEnabled <bool>] [-BrokerEnabled <bool>] [-ChangeTrackingAutoCleanUp <bool>] [-ChangeTrackingEnabled <bool>] [-CloseCursorsOnCommitEnabled <bool>] [-ConcatenateNullYieldsNull <bool>] [-DatabaseOwnershipChaining <bool>] [-DataRetentionEnabled <bool>] [-DateCorrelationOptimization <bool>] [-DelayedDurability <bool>] [-EncryptionEnabled <bool>] [-HonorBrokerPriority <bool>] [-IsFullTextEnabled <bool>] [-LegacyCardinalityEstimation <bool>] [-LegacyCardinalityEstimationForSecondary <bool>] [-LocalCursorsDefault <bool>] [-NestedTriggersEnabled <bool>] [-NumericRoundAbortEnabled <bool>] [-ParameterSniffing <bool>] [-ParameterSniffingForSecondary <bool>] [-QueryOptimizerHotfixes <bool>] [-QueryOptimizerHotfixesForSecondary <bool>] [-QuotedIdentifiersEnabled <bool>] [-ReadOnly <bool>] [-RecursiveTriggersEnabled <bool>] [-RemoteDataArchiveEnabled <bool>] [-RemoteDataArchiveUseFederatedServiceAccount <bool>] [-TemporalHistoryRetentionEnabled <bool>] [-TransformNoiseWords <bool>] [-Trustworthy <bool>] [-ChangeTrackingRetentionPeriod <int>] [-DefaultFullTextLanguage <int>] [-DefaultLanguage <int>] [-MaxDop <int>] [-MaxDopForSecondary <int>] [-MirroringRedoQueueMaxSize <int>] [-MirroringTimeout <int>] [-TargetRecoveryTime <int>] [-TwoDigitYearCutoff <int>] [-MaxSizeInBytes <long>] [-AzureServiceObjective <string>] [-Collation <string>] [-DefaultFileGroup <string>] [-DefaultFileStreamFileGroup <string>] [-DefaultFullTextCatalog <string>] [-DefaultSchema <string>] [-FilestreamDirectoryName <string>] [-MirroringPartner <string>] [-MirroringPartnerInstance <string>] [-MirroringWitness <string>] [-PersistentVersionStoreFileGroup <string>] [-PrimaryFilePath <string>] [-RemoteDataArchiveCredential <string>] [-RemoteDataArchiveEndpoint <string>] [-RemoteDataArchiveLinkedServer <string>] [-RemoteDatabaseName <string>] [-AzureEdition <string>] [-ChangeTrackingRetentionPeriodUnits <RetentionPeriodUnits>] [-CompatibilityLevel <CompatibilityLevel>] [-ContainmentType <ContainmentType>] [-FilestreamNonTransactedAccess <FilestreamNonTransactedAccessType>] [-MirroringSafetyLevel <MirroringSafetyLevel>] [-PageVerify <PageVerify>] [-RecoveryModel <RecoveryModel>] [-SnapshotIsolationState <SnapshotIsolationState>] [-UserAccess <DatabaseUserAccess>] [-Force] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]'
320+
ExpectedParameters = '-ServerObject <Server> -Name <string> [-Refresh] [-AcceleratedRecoveryEnabled <bool>] [-AnsiNullDefault <bool>] [-AnsiNullsEnabled <bool>] [-AnsiPaddingEnabled <bool>] [-AnsiWarningsEnabled <bool>] [-ArithmeticAbortEnabled <bool>] [-AutoClose <bool>] [-AutoCreateIncrementalStatisticsEnabled <bool>] [-AutoCreateStatisticsEnabled <bool>] [-AutoShrink <bool>] [-AutoUpdateStatisticsAsync <bool>] [-AutoUpdateStatisticsEnabled <bool>] [-BrokerEnabled <bool>] [-ChangeTrackingAutoCleanUp <bool>] [-ChangeTrackingEnabled <bool>] [-CloseCursorsOnCommitEnabled <bool>] [-ConcatenateNullYieldsNull <bool>] [-DatabaseOwnershipChaining <bool>] [-DataRetentionEnabled <bool>] [-DateCorrelationOptimization <bool>] [-DelayedDurability <bool>] [-EncryptionEnabled <bool>] [-HonorBrokerPriority <bool>] [-IsFullTextEnabled <bool>] [-LegacyCardinalityEstimation <bool>] [-LegacyCardinalityEstimationForSecondary <bool>] [-LocalCursorsDefault <bool>] [-NestedTriggersEnabled <bool>] [-NumericRoundAbortEnabled <bool>] [-ParameterSniffing <bool>] [-ParameterSniffingForSecondary <bool>] [-QueryOptimizerHotfixes <bool>] [-QueryOptimizerHotfixesForSecondary <bool>] [-QuotedIdentifiersEnabled <bool>] [-ReadOnly <bool>] [-RecursiveTriggersEnabled <bool>] [-RemoteDataArchiveEnabled <bool>] [-RemoteDataArchiveUseFederatedServiceAccount <bool>] [-TemporalHistoryRetentionEnabled <bool>] [-TransformNoiseWords <bool>] [-Trustworthy <bool>] [-ChangeTrackingRetentionPeriod <int>] [-DefaultFullTextLanguage <int>] [-DefaultLanguage <int>] [-MaxDop <int>] [-MaxDopForSecondary <int>] [-MirroringRedoQueueMaxSize <int>] [-MirroringTimeout <int>] [-TargetRecoveryTime <int>] [-TwoDigitYearCutoff <int>] [-MaxSizeInBytes <long>] [-AzureServiceObjective <string>] [-Collation <string>] [-DefaultFullTextCatalog <string>] [-DefaultSchema <string>] [-FilestreamDirectoryName <string>] [-MirroringPartner <string>] [-MirroringPartnerInstance <string>] [-MirroringWitness <string>] [-PersistentVersionStoreFileGroup <string>] [-PrimaryFilePath <string>] [-RemoteDataArchiveCredential <string>] [-RemoteDataArchiveEndpoint <string>] [-RemoteDataArchiveLinkedServer <string>] [-RemoteDatabaseName <string>] [-AzureEdition <string>] [-ChangeTrackingRetentionPeriodUnits <RetentionPeriodUnits>] [-CompatibilityLevel <CompatibilityLevel>] [-ContainmentType <ContainmentType>] [-FilestreamNonTransactedAccess <FilestreamNonTransactedAccessType>] [-MirroringSafetyLevel <MirroringSafetyLevel>] [-PageVerify <PageVerify>] [-RecoveryModel <RecoveryModel>] [-UserAccess <DatabaseUserAccess>] [-Force] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]'
321321
}
322322
) {
323323
$result = (Get-Command -Name 'Set-SqlDscDatabase').ParameterSets |
@@ -334,7 +334,7 @@ Describe 'Set-SqlDscDatabase' -Tag 'Public' {
334334
It 'Should have the correct parameters in parameter set DatabaseObjectSet' -ForEach @(
335335
@{
336336
ExpectedParameterSetName = 'DatabaseObjectSet'
337-
ExpectedParameters = '-DatabaseObject <Database> [-AcceleratedRecoveryEnabled <bool>] [-AnsiNullDefault <bool>] [-AnsiNullsEnabled <bool>] [-AnsiPaddingEnabled <bool>] [-AnsiWarningsEnabled <bool>] [-ArithmeticAbortEnabled <bool>] [-AutoClose <bool>] [-AutoCreateIncrementalStatisticsEnabled <bool>] [-AutoCreateStatisticsEnabled <bool>] [-AutoShrink <bool>] [-AutoUpdateStatisticsAsync <bool>] [-AutoUpdateStatisticsEnabled <bool>] [-BrokerEnabled <bool>] [-ChangeTrackingAutoCleanUp <bool>] [-ChangeTrackingEnabled <bool>] [-CloseCursorsOnCommitEnabled <bool>] [-ConcatenateNullYieldsNull <bool>] [-DatabaseOwnershipChaining <bool>] [-DataRetentionEnabled <bool>] [-DateCorrelationOptimization <bool>] [-DelayedDurability <bool>] [-EncryptionEnabled <bool>] [-HonorBrokerPriority <bool>] [-IsFullTextEnabled <bool>] [-LegacyCardinalityEstimation <bool>] [-LegacyCardinalityEstimationForSecondary <bool>] [-LocalCursorsDefault <bool>] [-NestedTriggersEnabled <bool>] [-NumericRoundAbortEnabled <bool>] [-ParameterSniffing <bool>] [-ParameterSniffingForSecondary <bool>] [-QueryOptimizerHotfixes <bool>] [-QueryOptimizerHotfixesForSecondary <bool>] [-QuotedIdentifiersEnabled <bool>] [-ReadOnly <bool>] [-RecursiveTriggersEnabled <bool>] [-RemoteDataArchiveEnabled <bool>] [-RemoteDataArchiveUseFederatedServiceAccount <bool>] [-TemporalHistoryRetentionEnabled <bool>] [-TransformNoiseWords <bool>] [-Trustworthy <bool>] [-ChangeTrackingRetentionPeriod <int>] [-DefaultFullTextLanguage <int>] [-DefaultLanguage <int>] [-MaxDop <int>] [-MaxDopForSecondary <int>] [-MirroringRedoQueueMaxSize <int>] [-MirroringTimeout <int>] [-TargetRecoveryTime <int>] [-TwoDigitYearCutoff <int>] [-MaxSizeInBytes <long>] [-AzureServiceObjective <string>] [-Collation <string>] [-DefaultFileGroup <string>] [-DefaultFileStreamFileGroup <string>] [-DefaultFullTextCatalog <string>] [-DefaultSchema <string>] [-FilestreamDirectoryName <string>] [-MirroringPartner <string>] [-MirroringPartnerInstance <string>] [-MirroringWitness <string>] [-PersistentVersionStoreFileGroup <string>] [-PrimaryFilePath <string>] [-RemoteDataArchiveCredential <string>] [-RemoteDataArchiveEndpoint <string>] [-RemoteDataArchiveLinkedServer <string>] [-RemoteDatabaseName <string>] [-AzureEdition <string>] [-ChangeTrackingRetentionPeriodUnits <RetentionPeriodUnits>] [-CompatibilityLevel <CompatibilityLevel>] [-ContainmentType <ContainmentType>] [-FilestreamNonTransactedAccess <FilestreamNonTransactedAccessType>] [-MirroringSafetyLevel <MirroringSafetyLevel>] [-PageVerify <PageVerify>] [-RecoveryModel <RecoveryModel>] [-SnapshotIsolationState <SnapshotIsolationState>] [-UserAccess <DatabaseUserAccess>] [-Force] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]'
337+
ExpectedParameters = '-DatabaseObject <Database> [-AcceleratedRecoveryEnabled <bool>] [-AnsiNullDefault <bool>] [-AnsiNullsEnabled <bool>] [-AnsiPaddingEnabled <bool>] [-AnsiWarningsEnabled <bool>] [-ArithmeticAbortEnabled <bool>] [-AutoClose <bool>] [-AutoCreateIncrementalStatisticsEnabled <bool>] [-AutoCreateStatisticsEnabled <bool>] [-AutoShrink <bool>] [-AutoUpdateStatisticsAsync <bool>] [-AutoUpdateStatisticsEnabled <bool>] [-BrokerEnabled <bool>] [-ChangeTrackingAutoCleanUp <bool>] [-ChangeTrackingEnabled <bool>] [-CloseCursorsOnCommitEnabled <bool>] [-ConcatenateNullYieldsNull <bool>] [-DatabaseOwnershipChaining <bool>] [-DataRetentionEnabled <bool>] [-DateCorrelationOptimization <bool>] [-DelayedDurability <bool>] [-EncryptionEnabled <bool>] [-HonorBrokerPriority <bool>] [-IsFullTextEnabled <bool>] [-LegacyCardinalityEstimation <bool>] [-LegacyCardinalityEstimationForSecondary <bool>] [-LocalCursorsDefault <bool>] [-NestedTriggersEnabled <bool>] [-NumericRoundAbortEnabled <bool>] [-ParameterSniffing <bool>] [-ParameterSniffingForSecondary <bool>] [-QueryOptimizerHotfixes <bool>] [-QueryOptimizerHotfixesForSecondary <bool>] [-QuotedIdentifiersEnabled <bool>] [-ReadOnly <bool>] [-RecursiveTriggersEnabled <bool>] [-RemoteDataArchiveEnabled <bool>] [-RemoteDataArchiveUseFederatedServiceAccount <bool>] [-TemporalHistoryRetentionEnabled <bool>] [-TransformNoiseWords <bool>] [-Trustworthy <bool>] [-ChangeTrackingRetentionPeriod <int>] [-DefaultFullTextLanguage <int>] [-DefaultLanguage <int>] [-MaxDop <int>] [-MaxDopForSecondary <int>] [-MirroringRedoQueueMaxSize <int>] [-MirroringTimeout <int>] [-TargetRecoveryTime <int>] [-TwoDigitYearCutoff <int>] [-MaxSizeInBytes <long>] [-AzureServiceObjective <string>] [-Collation <string>] [-DefaultFullTextCatalog <string>] [-DefaultSchema <string>] [-FilestreamDirectoryName <string>] [-MirroringPartner <string>] [-MirroringPartnerInstance <string>] [-MirroringWitness <string>] [-PersistentVersionStoreFileGroup <string>] [-PrimaryFilePath <string>] [-RemoteDataArchiveCredential <string>] [-RemoteDataArchiveEndpoint <string>] [-RemoteDataArchiveLinkedServer <string>] [-RemoteDatabaseName <string>] [-AzureEdition <string>] [-ChangeTrackingRetentionPeriodUnits <RetentionPeriodUnits>] [-CompatibilityLevel <CompatibilityLevel>] [-ContainmentType <ContainmentType>] [-FilestreamNonTransactedAccess <FilestreamNonTransactedAccessType>] [-MirroringSafetyLevel <MirroringSafetyLevel>] [-PageVerify <PageVerify>] [-RecoveryModel <RecoveryModel>] [-UserAccess <DatabaseUserAccess>] [-Force] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]'
338338
}
339339
) {
340340
$result = (Get-Command -Name 'Set-SqlDscDatabase').ParameterSets |

0 commit comments

Comments
 (0)