Skip to content

Commit 552b77a

Browse files
Invoke-DbaDbDataMasking - Fix StaticValue empty string fallback and FilterQuery in Actions (#10281)
1 parent c82ae19 commit 552b77a

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

public/Invoke-DbaDbDataMasking.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ function Invoke-DbaDbDataMasking {
842842
$newValue = $null
843843

844844
# Handle static values
845-
if ($columnobject.StaticValue) {
845+
if ($null -ne $columnobject.StaticValue) {
846846
$newValue = $columnobject.StaticValue
847847

848848
if ($null -eq $newValue -and -not $columnobject.Nullable) {
@@ -904,7 +904,7 @@ function Invoke-DbaDbDataMasking {
904904
}
905905

906906
# If we haven't determined a value yet, generate one
907-
if ($null -eq $newValue -and -not $columnobject.StaticValue) {
907+
if ($null -eq $newValue -and $null -eq $columnobject.StaticValue) {
908908
# make sure min is good
909909
if ($columnobject.MinValue) {
910910
$min = $columnobject.MinValue
@@ -1149,6 +1149,15 @@ function Invoke-DbaDbDataMasking {
11491149
}
11501150
}
11511151
}
1152+
# Add FilterQuery WHERE clause to restrict which rows are updated
1153+
if ($validAction -and $tableobject.FilterQuery) {
1154+
$filterParts = ($tableobject.FilterQuery) -split "WHERE", 2, "ignorecase"
1155+
if ($filterParts.Count -gt 1) {
1156+
$filterWhereClause = $filterParts[1].Trim().TrimEnd(";")
1157+
$query = $query.TrimEnd(";") + " WHERE $filterWhereClause;"
1158+
}
1159+
}
1160+
11521161
# Add the query to the rest
11531162
if ($validAction) {
11541163
$null = $stringBuilder.AppendLine($query)

0 commit comments

Comments
 (0)