Skip to content

Commit 4b7708d

Browse files
Copilotjohlju
andcommitted
Move IsLedger parameter from Set-SqlDscDatabaseProperty to New-SqlDscDatabase
Co-authored-by: johlju <[email protected]>
1 parent dd080ba commit 4b7708d

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
command with the `-DatabaseSnapshotBaseName` parameter.
2323
- Removed parameter `DefaultSchema`. Default schema is a user-level property,
2424
not a database-level property. See [issue #2177](https://github.com/dsccommunity/SqlServerDsc/issues/2177).
25+
- Removed parameter `IsLedger`. Ledger status is read-only after database creation.
26+
Use `New-SqlDscDatabase` with the `-IsLedger` parameter to create ledger databases
27+
[issue #2351](https://github.com/dsccommunity/SqlServerDsc/issues/2351).
2528

2629
### Added
2730

@@ -58,6 +61,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5861
database snapshots, enabling control over file placement for snapshots (sparse
5962
files) and custom filegroup/datafile configuration for regular databases
6063
([issue #2341](https://github.com/dsccommunity/SqlServerDsc/issues/2341)).
64+
- Added `IsLedger` parameter to support creating ledger databases at creation time.
65+
Ledger status is read-only after database creation and can only be set when
66+
creating a new database ([issue #2351](https://github.com/dsccommunity/SqlServerDsc/issues/2351)).
6167
- Added public command `Set-SqlDscDatabaseOwner` to change the owner of a SQL Server
6268
database [issue #2177](https://github.com/dsccommunity/SqlServerDsc/issues/2177).
6369
This command uses the SMO `SetOwner()` method and supports both `ServerObject`

source/Public/New-SqlDscDatabase.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
.PARAMETER OwnerName
3434
Specifies the name of the login that should be the owner of the database.
3535
36+
.PARAMETER IsLedger
37+
Specifies whether to create a ledger database. Ledger databases provide
38+
tamper-evidence capabilities and are immutable once created. This parameter
39+
can only be set during database creation - ledger status cannot be changed
40+
after the database is created. This parameter requires SQL Server 2022
41+
(version 16) or later, or Azure SQL Database.
42+
3643
.PARAMETER DatabaseSnapshotBaseName
3744
Specifies the name of the source database from which to create a snapshot.
3845
When this parameter is specified, a database snapshot will be created instead
@@ -138,6 +145,10 @@ function New-SqlDscDatabase
138145
[System.String]
139146
$OwnerName,
140147

148+
[Parameter(ParameterSetName = 'Database')]
149+
[System.Boolean]
150+
$IsLedger,
151+
141152
[Parameter(Mandatory = $true, ParameterSetName = 'Snapshot')]
142153
[ValidateNotNullOrEmpty()]
143154
[System.String]
@@ -312,6 +323,11 @@ function New-SqlDscDatabase
312323
{
313324
$sqlDatabaseObjectToCreate.CompatibilityLevel = $CompatibilityLevel
314325
}
326+
327+
if ($PSBoundParameters.ContainsKey('IsLedger'))
328+
{
329+
$sqlDatabaseObjectToCreate.IsLedger = $IsLedger
330+
}
315331
}
316332

317333
# Add FileGroups if provided (applies to both regular databases and snapshots)

source/Public/Set-SqlDscDatabaseProperty.ps1

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@
135135
.PARAMETER IsFullTextEnabled
136136
Specifies whether full-text search is enabled.
137137
138-
.PARAMETER IsLedger
139-
Specifies whether the database is a ledger database.
140-
141138
.PARAMETER IsParameterizationForced
142139
Specifies whether forced parameterization is enabled for the database.
143140
@@ -312,6 +309,11 @@
312309
class. To create database snapshots, use the `New-SqlDscDatabaseSnapshot` or
313310
`New-SqlDscDatabase` command with the `-DatabaseSnapshotBaseName` parameter.
314311
312+
- **IsLedger**: Specifies whether the database is a ledger database. Ledger
313+
status can only be set during database creation using the `New-SqlDscDatabase`
314+
command with the `-IsLedger` parameter. Once a database is created, its ledger
315+
status cannot be changed.
316+
315317
There are some database properties that require method calls instead of direct
316318
property assignment and will be supported through separate commands, e.g.
317319
`Set-SqlDscDatabaseDefaultFileGroup`.
@@ -439,10 +441,6 @@ function Set-SqlDscDatabaseProperty
439441
[System.Boolean]
440442
$IsFullTextEnabled,
441443

442-
[Parameter()]
443-
[System.Boolean]
444-
$IsLedger,
445-
446444
[Parameter()]
447445
[System.Boolean]
448446
$IsParameterizationForced,

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ Describe 'New-SqlDscDatabase' -Tag 'Public' {
7373
$mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'RecoveryModel' -Value $null -Force
7474
$mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'Collation' -Value $null -Force
7575
$mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'CompatibilityLevel' -Value $null -Force
76+
$mockDatabaseObject | Add-Member -MemberType 'NoteProperty' -Name 'IsLedger' -Value $false -Force
7677
$mockDatabaseObject | Add-Member -MemberType 'ScriptMethod' -Name 'Create' -Value {
7778
# Mock implementation
7879
} -Force
@@ -102,6 +103,14 @@ Describe 'New-SqlDscDatabase' -Tag 'Public' {
102103
$result.CompatibilityLevel | Should -Be 'Version150'
103104
}
104105

106+
It 'Should create a ledger database with IsLedger set to true' {
107+
$result = New-SqlDscDatabase -ServerObject $mockServerObject -Name 'LedgerDatabase' -IsLedger $true -Force
108+
109+
$result | Should -Not -BeNullOrEmpty
110+
$result.Name | Should -Be 'LedgerDatabase'
111+
$result.IsLedger | Should -BeTrue
112+
}
113+
105114
It 'Should throw error when database already exists' {
106115
$mockServerObjectWithExistingDb = New-Object -TypeName 'Microsoft.SqlServer.Management.Smo.Server'
107116
$mockServerObjectWithExistingDb | Add-Member -MemberType 'NoteProperty' -Name 'InstanceName' -Value 'TestInstance' -Force
@@ -157,7 +166,7 @@ Describe 'New-SqlDscDatabase' -Tag 'Public' {
157166
It 'Should have the correct parameters in parameter set Database' -ForEach @(
158167
@{
159168
ExpectedParameterSetName = 'Database'
160-
ExpectedParameters = '-ServerObject <Server> -Name <string> [-Collation <string>] [-CatalogCollation <CatalogCollationType>] [-CompatibilityLevel <string>] [-RecoveryModel <string>] [-OwnerName <string>] [-FileGroup <DatabaseFileGroupSpec[]>] [-Force] [-Refresh] [-WhatIf] [-Confirm] [<CommonParameters>]'
169+
ExpectedParameters = '-ServerObject <Server> -Name <string> [-Collation <string>] [-CatalogCollation <CatalogCollationType>] [-CompatibilityLevel <string>] [-RecoveryModel <string>] [-OwnerName <string>] [-IsLedger <bool>] [-FileGroup <DatabaseFileGroupSpec[]>] [-Force] [-Refresh] [-WhatIf] [-Confirm] [<CommonParameters>]'
161170
}
162171
) {
163172
$result = (Get-Command -Name 'New-SqlDscDatabase').ParameterSets |
@@ -203,6 +212,12 @@ Describe 'New-SqlDscDatabase' -Tag 'Public' {
203212
$snapshotSetAttribute = $parameterInfo.Attributes | Where-Object { $_.ParameterSetName -eq 'Snapshot' }
204213
$snapshotSetAttribute.Mandatory | Should -BeTrue
205214
}
215+
216+
It 'Should have IsLedger as a parameter in Database parameter set' {
217+
$parameterInfo = (Get-Command -Name 'New-SqlDscDatabase').Parameters['IsLedger']
218+
$databaseSetAttribute = $parameterInfo.Attributes | Where-Object { $_.ParameterSetName -eq 'Database' }
219+
$databaseSetAttribute | Should -Not -BeNullOrEmpty
220+
}
206221
}
207222

208223
Context 'When creating a database snapshot' {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ Describe 'Set-SqlDscDatabaseProperty' -Tag 'Public' {
366366
It 'Should have the correct parameters in parameter set ServerObjectSet' -ForEach @(
367367
@{
368368
ExpectedParameterSetName = 'ServerObjectSet'
369-
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>] [-EncryptionEnabled <bool>] [-HonorBrokerPriority <bool>] [-IsFullTextEnabled <bool>] [-IsLedger <bool>] [-IsParameterizationForced <bool>] [-IsReadCommittedSnapshotOn <bool>] [-IsSqlDw <bool>] [-IsVarDecimalStorageFormatEnabled <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 <double>] [-Collation <string>] [-FilestreamDirectoryName <string>] [-MirroringPartner <string>] [-MirroringPartnerInstance <string>] [-MirroringWitness <string>] [-PersistentVersionStoreFileGroup <string>] [-PrimaryFilePath <string>] [-RemoteDataArchiveCredential <string>] [-RemoteDataArchiveEndpoint <string>] [-RemoteDataArchiveLinkedServer <string>] [-RemoteDatabaseName <string>] [-ChangeTrackingRetentionPeriodUnits <RetentionPeriodUnits>] [-CompatibilityLevel <CompatibilityLevel>] [-ContainmentType <ContainmentType>] [-DelayedDurability <DelayedDurability>] [-FilestreamNonTransactedAccess <FilestreamNonTransactedAccessType>] [-MirroringSafetyLevel <MirroringSafetyLevel>] [-PageVerify <PageVerify>] [-RecoveryModel <RecoveryModel>] [-UserAccess <DatabaseUserAccess>] [-Force] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]'
369+
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>] [-EncryptionEnabled <bool>] [-HonorBrokerPriority <bool>] [-IsFullTextEnabled <bool>] [-IsParameterizationForced <bool>] [-IsReadCommittedSnapshotOn <bool>] [-IsSqlDw <bool>] [-IsVarDecimalStorageFormatEnabled <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 <double>] [-Collation <string>] [-FilestreamDirectoryName <string>] [-MirroringPartner <string>] [-MirroringPartnerInstance <string>] [-MirroringWitness <string>] [-PersistentVersionStoreFileGroup <string>] [-PrimaryFilePath <string>] [-RemoteDataArchiveCredential <string>] [-RemoteDataArchiveEndpoint <string>] [-RemoteDataArchiveLinkedServer <string>] [-RemoteDatabaseName <string>] [-ChangeTrackingRetentionPeriodUnits <RetentionPeriodUnits>] [-CompatibilityLevel <CompatibilityLevel>] [-ContainmentType <ContainmentType>] [-DelayedDurability <DelayedDurability>] [-FilestreamNonTransactedAccess <FilestreamNonTransactedAccessType>] [-MirroringSafetyLevel <MirroringSafetyLevel>] [-PageVerify <PageVerify>] [-RecoveryModel <RecoveryModel>] [-UserAccess <DatabaseUserAccess>] [-Force] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]'
370370
}
371371
) {
372372
$result = (Get-Command -Name 'Set-SqlDscDatabaseProperty').ParameterSets |
@@ -383,7 +383,7 @@ Describe 'Set-SqlDscDatabaseProperty' -Tag 'Public' {
383383
It 'Should have the correct parameters in parameter set DatabaseObjectSet' -ForEach @(
384384
@{
385385
ExpectedParameterSetName = 'DatabaseObjectSet'
386-
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>] [-EncryptionEnabled <bool>] [-HonorBrokerPriority <bool>] [-IsFullTextEnabled <bool>] [-IsLedger <bool>] [-IsParameterizationForced <bool>] [-IsReadCommittedSnapshotOn <bool>] [-IsSqlDw <bool>] [-IsVarDecimalStorageFormatEnabled <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 <double>] [-Collation <string>] [-FilestreamDirectoryName <string>] [-MirroringPartner <string>] [-MirroringPartnerInstance <string>] [-MirroringWitness <string>] [-PersistentVersionStoreFileGroup <string>] [-PrimaryFilePath <string>] [-RemoteDataArchiveCredential <string>] [-RemoteDataArchiveEndpoint <string>] [-RemoteDataArchiveLinkedServer <string>] [-RemoteDatabaseName <string>] [-ChangeTrackingRetentionPeriodUnits <RetentionPeriodUnits>] [-CompatibilityLevel <CompatibilityLevel>] [-ContainmentType <ContainmentType>] [-DelayedDurability <DelayedDurability>] [-FilestreamNonTransactedAccess <FilestreamNonTransactedAccessType>] [-MirroringSafetyLevel <MirroringSafetyLevel>] [-PageVerify <PageVerify>] [-RecoveryModel <RecoveryModel>] [-UserAccess <DatabaseUserAccess>] [-Force] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]'
386+
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>] [-EncryptionEnabled <bool>] [-HonorBrokerPriority <bool>] [-IsFullTextEnabled <bool>] [-IsParameterizationForced <bool>] [-IsReadCommittedSnapshotOn <bool>] [-IsSqlDw <bool>] [-IsVarDecimalStorageFormatEnabled <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 <double>] [-Collation <string>] [-FilestreamDirectoryName <string>] [-MirroringPartner <string>] [-MirroringPartnerInstance <string>] [-MirroringWitness <string>] [-PersistentVersionStoreFileGroup <string>] [-PrimaryFilePath <string>] [-RemoteDataArchiveCredential <string>] [-RemoteDataArchiveEndpoint <string>] [-RemoteDataArchiveLinkedServer <string>] [-RemoteDatabaseName <string>] [-ChangeTrackingRetentionPeriodUnits <RetentionPeriodUnits>] [-CompatibilityLevel <CompatibilityLevel>] [-ContainmentType <ContainmentType>] [-DelayedDurability <DelayedDurability>] [-FilestreamNonTransactedAccess <FilestreamNonTransactedAccessType>] [-MirroringSafetyLevel <MirroringSafetyLevel>] [-PageVerify <PageVerify>] [-RecoveryModel <RecoveryModel>] [-UserAccess <DatabaseUserAccess>] [-Force] [-PassThru] [-WhatIf] [-Confirm] [<CommonParameters>]'
387387
}
388388
) {
389389
$result = (Get-Command -Name 'Set-SqlDscDatabaseProperty').ParameterSets |

0 commit comments

Comments
 (0)