Skip to content

Commit 90bf1e2

Browse files
committed
add more undocumented relations
1 parent 1d61cc3 commit 90bf1e2

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

services/cleanup/relations.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
from django.db.models import Model, Q
66
from django.db.models.query import QuerySet
7+
from shared.django_apps.bundle_analysis.models import CacheConfig
78
from shared.django_apps.codecov_auth.models import Owner, OwnerProfile
89
from shared.django_apps.core.models import Commit, Pull, Repository
910
from shared.django_apps.reports.models import DailyTestRollup, TestInstance
11+
from shared.django_apps.user_measurements.models import UserMeasurement
1012

1113
# Relations referencing 0 through field 1 of model 2:
1214
IGNORE_RELATIONS: set[tuple[type[Model], str, type[Model]]] = {
@@ -19,10 +21,16 @@
1921
}
2022

2123
# Relations which have no proper foreign key:
22-
UNDOCUMENTED_RELATIONS: set[tuple[type[Model], str, type[Model]]] = {
24+
UNDOCUMENTED_RELATIONS: list[tuple[type[Model], str, type[Model]]] = [
2325
(Repository, "repoid", TestInstance),
2426
(Repository, "repoid", DailyTestRollup),
25-
}
27+
(Commit, "commit_id", UserMeasurement),
28+
(Owner, "owner_id", UserMeasurement),
29+
(Repository, "repo_id", UserMeasurement),
30+
(Repository, "repo_id", CacheConfig),
31+
# TODO: `UserMeasurement` also has `upload_id`, should we register that as well?
32+
# TODO: should we also include `SimpleMetric` here?
33+
]
2634

2735

2836
@dataclasses.dataclass

services/cleanup/tests/snapshots/relations__builds_delete_queries__owner.txt

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
-- UserMeasurement
2+
DELETE
3+
FROM "user_measurements"
4+
WHERE "user_measurements"."owner_id" IN
5+
(SELECT U0."ownerid"
6+
FROM "owners" U0
7+
WHERE U0."ownerid" = %s)
8+
9+
110
-- YamlHistory
211
DELETE
312
FROM "yaml_history"
@@ -92,6 +101,18 @@ WHERE "reports_dailytestrollups"."repoid" IN
92101
WHERE U0."ownerid" = %s))
93102

94103

104+
-- CacheConfig
105+
DELETE
106+
FROM "bundle_analysis_cacheconfig"
107+
WHERE "bundle_analysis_cacheconfig"."repo_id" IN
108+
(SELECT V0."repoid"
109+
FROM "repos" V0
110+
WHERE V0."ownerid" IN
111+
(SELECT U0."ownerid"
112+
FROM "owners" U0
113+
WHERE U0."ownerid" = %s))
114+
115+
95116
-- RepositoryToken
96117
DELETE
97118
FROM "codecov_auth_repositorytoken"

services/cleanup/tests/snapshots/relations__builds_delete_queries__repository.txt

+18
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ WHERE "reports_dailytestrollups"."repoid" IN
1616
WHERE U0."repoid" = %s)
1717

1818

19+
-- UserMeasurement
20+
DELETE
21+
FROM "user_measurements"
22+
WHERE "user_measurements"."repo_id" IN
23+
(SELECT U0."repoid"
24+
FROM "repos" U0
25+
WHERE U0."repoid" = %s)
26+
27+
28+
-- CacheConfig
29+
DELETE
30+
FROM "bundle_analysis_cacheconfig"
31+
WHERE "bundle_analysis_cacheconfig"."repo_id" IN
32+
(SELECT U0."repoid"
33+
FROM "repos" U0
34+
WHERE U0."repoid" = %s)
35+
36+
1937
-- RepositoryToken
2038
DELETE
2139
FROM "codecov_auth_repositorytoken"

0 commit comments

Comments
 (0)