From fe4c353bf34369e8f5b791a8ef461e60b66e57e4 Mon Sep 17 00:00:00 2001 From: Teddy Date: Fri, 22 Dec 2023 11:01:51 +0100 Subject: [PATCH] Fixes #14331 - Add Test Case Incident Manager Migration (#14386) * feat: add test case resolution task workflow * chore: add migration for test case resolution feature * fix: removed required field for object compatibiity in older migrations * fix: minor testCaseResolution status logic * chore: revert migration for test case incident * chore: update migration file * chore: clean up code * style: fix java stylecheck --- .../1.3.0/mysql/postDataMigrationSQLScript.sql | 16 ++++++++++++++-- .../postgres/postDataMigrationSQLScript.sql | 11 ++++++++++- .../TestCaseResolutionStatusRepository.java | 1 + .../resources/dqtests/TestCaseResourceTest.java | 2 +- .../main/resources/json/schema/tests/basic.json | 3 +-- .../resources/json/schema/tests/resolved.json | 2 +- 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/bootstrap/sql/migrations/native/1.3.0/mysql/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.3.0/mysql/postDataMigrationSQLScript.sql index e66612d8f5f..31e8e3d7a05 100644 --- a/bootstrap/sql/migrations/native/1.3.0/mysql/postDataMigrationSQLScript.sql +++ b/bootstrap/sql/migrations/native/1.3.0/mysql/postDataMigrationSQLScript.sql @@ -4,5 +4,17 @@ SET json = REPLACE(json, '"customMetricsProfile"', '"customMetrics"'); -- Delete customMetricsProfile from entity_extension -- This was not supported on the processing side before 1.3. -DELETE FROM openmetadata_db.entity_extension ee -where extension like '%customMetrics'; \ No newline at end of file +DELETE FROM entity_extension ee +where extension like '%customMetrics'; + +-- BEGIN: Incident Manager Migration +-- STEP 1: Update test case testCaseResult.testCaseFailureStatus field +UPDATE test_case +SET json = JSON_REMOVE(json, '$.testCaseResult.testCaseFailureStatus') +WHERE json -> '$.testCaseResult.testCaseFailureStatus' IS NOT NULL; + + +-- STEP 2: remove all `testCaseFailureStatus` field in test results +UPDATE data_quality_data_time_series d +SET json = JSON_REMOVE(json, '$.testCaseFailureStatus'); +-- END: Incident Manager Migration diff --git a/bootstrap/sql/migrations/native/1.3.0/postgres/postDataMigrationSQLScript.sql b/bootstrap/sql/migrations/native/1.3.0/postgres/postDataMigrationSQLScript.sql index 6d65e5f7705..9a8da76d669 100644 --- a/bootstrap/sql/migrations/native/1.3.0/postgres/postDataMigrationSQLScript.sql +++ b/bootstrap/sql/migrations/native/1.3.0/postgres/postDataMigrationSQLScript.sql @@ -5,4 +5,13 @@ SET json = REPLACE(json::text, '"customMetricsProfile"', '"customMetrics"')::jso -- Delete customMetricsProfile from entity_extension -- This was not supported on the processing side before 1.3. DELETE FROM entity_extension ee -where extension like '%customMetrics'; \ No newline at end of file +where extension like '%customMetrics'; + +-- BEGIN: Incident Manager Migration +-- STEP 1: Update test case testCaseResult.testCaseFailureStatus field +UPDATE test_case +SET json = json::jsonb#-'{testCaseResult,testCaseFailureStatus}'; +-- STEP 2: remove all `testCaseFailureStatus` field in test results +UPDATE data_quality_data_time_series d +SET json = json::jsonb#-'{testCaseFailureStatus}'; +-- END: Incident Manager Migration \ No newline at end of file diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseResolutionStatusRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseResolutionStatusRepository.java index 7cd6839a4ed..5cf814930d8 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseResolutionStatusRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TestCaseResolutionStatusRepository.java @@ -110,6 +110,7 @@ public class TestCaseResolutionStatusRepository TestCaseResolutionStatus recordEntity, String extension, String recordFQN) { TestCaseResolutionStatus latestTestCaseFailure = getLatestRecord(recordEntity.getTestCaseReference().getFullyQualifiedName()); + recordEntity.setStateId( ((latestTestCaseFailure != null) && (latestTestCaseFailure.getTestCaseResolutionStatusType() diff --git a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java index 442e153485a..a7b45e2c941 100644 --- a/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java +++ b/openmetadata-service/src/test/java/org/openmetadata/service/resources/dqtests/TestCaseResourceTest.java @@ -1770,7 +1770,7 @@ public class TestCaseResourceTest extends EntityResourceTest getTestCaseFailureStatus( + public ResultList getTestCaseFailureStatus( Long startTs, Long endTs, String assignee, diff --git a/openmetadata-spec/src/main/resources/json/schema/tests/basic.json b/openmetadata-spec/src/main/resources/json/schema/tests/basic.json index f4967673c5c..7832249cc37 100644 --- a/openmetadata-spec/src/main/resources/json/schema/tests/basic.json +++ b/openmetadata-spec/src/main/resources/json/schema/tests/basic.json @@ -90,8 +90,7 @@ "description": "Reference to the failure status object for the test case result.", "$ref": "./testCaseResolutionStatus.json" } - }, - "additionalProperties": false + } }, "testSuiteExecutionFrequency": { "description": "How often the test case should run.", diff --git a/openmetadata-spec/src/main/resources/json/schema/tests/resolved.json b/openmetadata-spec/src/main/resources/json/schema/tests/resolved.json index 54933b15a09..d15b6a1c9da 100644 --- a/openmetadata-spec/src/main/resources/json/schema/tests/resolved.json +++ b/openmetadata-spec/src/main/resources/json/schema/tests/resolved.json @@ -34,6 +34,6 @@ "$ref": "../type/entityReference.json" } }, - "required": ["testCaseFailureReason", "resolvedBy", "testCaseFailureComment"], + "required": ["testCaseFailureReason", "testCaseFailureComment"], "additionalProperties": false } \ No newline at end of file