From 0a043ca036b46134e7480f264f900f24fee38f95 Mon Sep 17 00:00:00 2001 From: Omar Selo Date: Wed, 9 Oct 2024 07:57:37 +0000 Subject: [PATCH] Remove review information from TestExecution db table --- ..._create_artefactbuildenvironmentreview_.py | 46 +++++++++++++++++++ backend/test_observer/data_access/models.py | 12 ----- .../test_observer/data_access/models_enums.py | 11 ----- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/backend/migrations/versions/2024_10_02_1114-91e7e3f437a0_create_artefactbuildenvironmentreview_.py b/backend/migrations/versions/2024_10_02_1114-91e7e3f437a0_create_artefactbuildenvironmentreview_.py index 0a087500..d2708fcb 100644 --- a/backend/migrations/versions/2024_10_02_1114-91e7e3f437a0_create_artefactbuildenvironmentreview_.py +++ b/backend/migrations/versions/2024_10_02_1114-91e7e3f437a0_create_artefactbuildenvironmentreview_.py @@ -25,6 +25,15 @@ ORDER BY id """ +reverse_copy_cmd = """ +UPDATE test_execution te + SET review_comment = aber.review_comment, + review_decision = aber.review_decision::TEXT[]::testexecutionreviewdecision[] + FROM artefact_build_environment_review aber + WHERE te.environment_id = aber.environment_id + AND te.artefact_build_id = aber.artefact_build_id +""" + def upgrade() -> None: op.create_table( @@ -76,7 +85,44 @@ def upgrade() -> None: op.execute(copy_cmd) + op.drop_column("test_execution", "review_comment") + op.drop_column("test_execution", "review_decision") + op.execute("DROP TYPE testexecutionreviewdecision") + def downgrade() -> None: + te_review_decision = sa.Enum( + "REJECTED", + "APPROVED_INCONSISTENT_TEST", + "APPROVED_UNSTABLE_PHYSICAL_INFRA", + "APPROVED_FAULTY_HARDWARE", + "APPROVED_CUSTOMER_PREREQUISITE_FAIL", + "APPROVED_ALL_TESTS_PASS", + name="testexecutionreviewdecision", + ) + te_review_decision.create(op.get_bind()) + op.add_column( + "test_execution", + sa.Column( + "review_decision", + postgresql.ARRAY(te_review_decision), + server_default=sa.text("'{}'::testexecutionreviewdecision[]"), + autoincrement=False, + nullable=False, + ), + ) + op.add_column( + "test_execution", + sa.Column( + "review_comment", + sa.VARCHAR(), + server_default=sa.text("''::character varying"), + autoincrement=False, + nullable=False, + ), + ) + + op.execute(reverse_copy_cmd) + op.drop_table("artefact_build_environment_review") op.execute("DROP TYPE artefactbuildenvironmentreviewdecision") diff --git a/backend/test_observer/data_access/models.py b/backend/test_observer/data_access/models.py index 1a381f6f..cf2b6121 100644 --- a/backend/test_observer/data_access/models.py +++ b/backend/test_observer/data_access/models.py @@ -45,7 +45,6 @@ from test_observer.data_access.models_enums import ( ArtefactBuildEnvironmentReviewDecision, ArtefactStatus, - TestExecutionReviewDecision, TestExecutionStatus, TestResultStatus, ) @@ -354,22 +353,11 @@ class TestExecution(Base): status: Mapped[TestExecutionStatus] = mapped_column( default=TestExecutionStatus.NOT_STARTED ) - review_decision: Mapped[list[TestExecutionReviewDecision]] = mapped_column( - ARRAY(Enum(TestExecutionReviewDecision)), - default=[], - ) - review_comment: Mapped[str] = mapped_column(default="") checkbox_version: Mapped[str | None] = mapped_column( String(200), nullable=True, default=None ) - @property - def is_approved(self) -> bool: - return (len(self.review_decision) > 0) and ( - TestExecutionReviewDecision.REJECTED not in self.review_decision - ) - @property def has_failures(self) -> bool: return any(tr.status == TestResultStatus.FAILED for tr in self.test_results) diff --git a/backend/test_observer/data_access/models_enums.py b/backend/test_observer/data_access/models_enums.py index c1a0f005..2c356376 100644 --- a/backend/test_observer/data_access/models_enums.py +++ b/backend/test_observer/data_access/models_enums.py @@ -38,17 +38,6 @@ class TestExecutionStatus(str, Enum): ENDED_PREMATURELY = "ENDED_PREMATURELY" -class TestExecutionReviewDecision(str, Enum): - __test__ = False - - REJECTED = "REJECTED" - APPROVED_INCONSISTENT_TEST = "APPROVED_INCONSISTENT_TEST" - APPROVED_UNSTABLE_PHYSICAL_INFRA = "APPROVED_UNSTABLE_PHYSICAL_INFRA" - APPROVED_CUSTOMER_PREREQUISITE_FAIL = "APPROVED_CUSTOMER_PREREQUISITE_FAIL" - APPROVED_FAULTY_HARDWARE = "APPROVED_FAULTY_HARDWARE" - APPROVED_ALL_TESTS_PASS = "APPROVED_ALL_TESTS_PASS" - - class ArtefactBuildEnvironmentReviewDecision(str, Enum): REJECTED = "REJECTED" APPROVED_INCONSISTENT_TEST = "APPROVED_INCONSISTENT_TEST"