Skip to content

Commit 94cbd50

Browse files
committed
Remove nullable attribute from CompatibilityLevel property and validate value before assignment
1 parent 483c937 commit 94cbd50

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

source/Classes/020.SqlDatabase.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class SqlDatabase : SqlResourceBase
337337
$Collation
338338

339339
[DscProperty()]
340-
[Nullable[DatabaseCompatibilityLevel]]
340+
[DatabaseCompatibilityLevel]
341341
$CompatibilityLevel
342342

343343
[DscProperty()]
@@ -738,7 +738,13 @@ class SqlDatabase : SqlResourceBase
738738

739739
# Basic properties
740740
$currentState.Collation = $databaseObject.Collation
741-
$currentState.CompatibilityLevel = [DatabaseCompatibilityLevel] $databaseObject.CompatibilityLevel.ToString()
741+
742+
# Only set CompatibilityLevel if it's a valid non-zero value
743+
if ($databaseObject.CompatibilityLevel -gt 0)
744+
{
745+
$currentState.CompatibilityLevel = [DatabaseCompatibilityLevel] $databaseObject.CompatibilityLevel.ToString()
746+
}
747+
742748
$currentState.RecoveryModel = $databaseObject.RecoveryModel.ToString()
743749
$currentState.OwnerName = $databaseObject.Owner
744750
$currentState.SnapshotIsolation = $databaseObject.SnapshotIsolationState -eq 'Enabled'

0 commit comments

Comments
 (0)