Skip to content

Commit

Permalink
add more undocumented relations
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Jan 20, 2025
1 parent 1d61cc3 commit 3653469
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 6 deletions.
8 changes: 8 additions & 0 deletions services/cleanup/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]] = {
Expand All @@ -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?
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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"
Expand Down

0 comments on commit 3653469

Please sign in to comment.