migration: fix duplicate param key insertion (#20802)

This commit is contained in:
Teddy 2025-04-15 14:10:51 +02:00 committed by GitHub
parent 1a6224824b
commit 98c6b6e4ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 5 deletions

View File

@ -14,4 +14,5 @@ SET json = JSON_MERGE_PRESERVE(
)
)
)
WHERE name = 'tableDiff';
WHERE name = 'tableDiff'
AND NOT JSON_CONTAINS(json->>'$.parameterDefinition', JSON_OBJECT('name', 'caseSensitiveColumns'));

View File

@ -5,4 +5,9 @@ SET json = jsonb_set(
(json->'parameterDefinition')::jsonb ||
'{"name": "caseSensitiveColumns", "dataType": "BOOLEAN", "required": false, "description": "Use case sensitivity when comparing the columns.", "displayName": "Case sensitive columns"}'::jsonb
)
WHERE name = 'tableDiff';
WHERE name = 'tableDiff'
AND NOT EXISTS (
SELECT 1
FROM jsonb_array_elements(json#>'{parameterDefinition}') AS elem
WHERE elem->>'name' = 'caseSensitiveColumns'
);

View File

@ -37,9 +37,14 @@ public class MigrationUtil {
TestDefinition td = getTestDefinition(daoCollection, testCase);
if (Objects.nonNull(td) && Objects.equals(td.getName(), TABLE_DIFF)) {
LOG.debug("Adding caseSensitiveColumns=true table diff test case: {}", testCase.getId());
testCase
.getParameterValues()
.add(new TestCaseParameterValue().withName("caseSensitiveColumns").withValue("true"));
if (!hasCaseSensitiveColumnsParam(testCase.getParameterValues())) {
testCase
.getParameterValues()
.add(
new TestCaseParameterValue()
.withName("caseSensitiveColumns")
.withValue("true"));
}
daoCollection.testCaseDAO().update(testCase);
}
}
@ -60,4 +65,10 @@ public class MigrationUtil {
}
return dao.testDefinitionDAO().findEntityById(records.get(0).getId());
}
private static boolean hasCaseSensitiveColumnsParam(
List<TestCaseParameterValue> parameterValues) {
return parameterValues.stream()
.anyMatch(paramValue -> paramValue.getName().equals("caseSensitiveColumns"));
}
}