From 365346981ca184317e4ebf536591e2ab2e11f3f2 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Mon, 20 Jan 2025 10:35:45 +0100 Subject: [PATCH] add more undocumented relations --- services/cleanup/relations.py | 8 ++++++ ...elations__builds_delete_queries__owner.txt | 27 ++++++++++++++++--- ...ons__builds_delete_queries__repository.txt | 24 ++++++++++++++--- 3 files changed, 53 insertions(+), 6 deletions(-) diff --git a/services/cleanup/relations.py b/services/cleanup/relations.py index aa58ad8ab..165f8cb9f 100644 --- a/services/cleanup/relations.py +++ b/services/cleanup/relations.py @@ -4,9 +4,11 @@ from django.db.models import Model, Q from django.db.models.query import QuerySet +from shared.django_apps.bundle_analysis.models import CacheConfig from shared.django_apps.codecov_auth.models import Owner, OwnerProfile from shared.django_apps.core.models import Commit, Pull, Repository from shared.django_apps.reports.models import DailyTestRollup, TestInstance +from shared.django_apps.user_measurements.models import UserMeasurement # Relations referencing 0 through field 1 of model 2: IGNORE_RELATIONS: set[tuple[type[Model], str, type[Model]]] = { @@ -22,6 +24,12 @@ UNDOCUMENTED_RELATIONS: set[tuple[type[Model], str, type[Model]]] = { (Repository, "repoid", TestInstance), (Repository, "repoid", DailyTestRollup), + (Commit, "commit_id", UserMeasurement), + (Owner, "owner_id", UserMeasurement), + (Repository, "repo_id", UserMeasurement), + (Repository, "repo_id", CacheConfig), + # TODO: `UserMeasurement` also has `upload_id`, should we register that as well? + # TODO: should we also include `SimpleMetric` here? } diff --git a/services/cleanup/tests/snapshots/relations__builds_delete_queries__owner.txt b/services/cleanup/tests/snapshots/relations__builds_delete_queries__owner.txt index 1cbb4f8c4..4174d9c56 100644 --- a/services/cleanup/tests/snapshots/relations__builds_delete_queries__owner.txt +++ b/services/cleanup/tests/snapshots/relations__builds_delete_queries__owner.txt @@ -1,3 +1,12 @@ +-- UserMeasurement +DELETE +FROM "user_measurements" +WHERE "user_measurements"."owner_id" IN + (SELECT U0."ownerid" + FROM "owners" U0 + WHERE U0."ownerid" = %s) + + -- YamlHistory DELETE FROM "yaml_history" @@ -68,10 +77,10 @@ WHERE "codecov_auth_usertoken"."ownerid" IN WHERE U0."ownerid" = %s) --- TestInstance +-- CacheConfig DELETE -FROM "reports_testinstance" -WHERE "reports_testinstance"."repoid" IN +FROM "bundle_analysis_cacheconfig" +WHERE "bundle_analysis_cacheconfig"."repo_id" IN (SELECT V0."repoid" FROM "repos" V0 WHERE V0."ownerid" IN @@ -92,6 +101,18 @@ WHERE "reports_dailytestrollups"."repoid" IN WHERE U0."ownerid" = %s)) +-- TestInstance +DELETE +FROM "reports_testinstance" +WHERE "reports_testinstance"."repoid" IN + (SELECT V0."repoid" + FROM "repos" V0 + WHERE V0."ownerid" IN + (SELECT U0."ownerid" + FROM "owners" U0 + WHERE U0."ownerid" = %s)) + + -- RepositoryToken DELETE FROM "codecov_auth_repositorytoken" diff --git a/services/cleanup/tests/snapshots/relations__builds_delete_queries__repository.txt b/services/cleanup/tests/snapshots/relations__builds_delete_queries__repository.txt index bac493729..7902c1fe7 100644 --- a/services/cleanup/tests/snapshots/relations__builds_delete_queries__repository.txt +++ b/services/cleanup/tests/snapshots/relations__builds_delete_queries__repository.txt @@ -1,7 +1,7 @@ --- TestInstance +-- CacheConfig DELETE -FROM "reports_testinstance" -WHERE "reports_testinstance"."repoid" IN +FROM "bundle_analysis_cacheconfig" +WHERE "bundle_analysis_cacheconfig"."repo_id" IN (SELECT U0."repoid" FROM "repos" U0 WHERE U0."repoid" = %s) @@ -16,6 +16,24 @@ WHERE "reports_dailytestrollups"."repoid" IN WHERE U0."repoid" = %s) +-- TestInstance +DELETE +FROM "reports_testinstance" +WHERE "reports_testinstance"."repoid" IN + (SELECT U0."repoid" + FROM "repos" U0 + WHERE U0."repoid" = %s) + + +-- UserMeasurement +DELETE +FROM "user_measurements" +WHERE "user_measurements"."repo_id" IN + (SELECT U0."repoid" + FROM "repos" U0 + WHERE U0."repoid" = %s) + + -- RepositoryToken DELETE FROM "codecov_auth_repositorytoken"