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 90bf1e2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
12 changes: 10 additions & 2 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 @@ -19,10 +21,16 @@
}

# Relations which have no proper foreign key:
UNDOCUMENTED_RELATIONS: set[tuple[type[Model], str, type[Model]]] = {
UNDOCUMENTED_RELATIONS: list[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?
]


@dataclasses.dataclass
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 @@ -92,6 +101,18 @@ WHERE "reports_dailytestrollups"."repoid" IN
WHERE U0."ownerid" = %s))


-- CacheConfig
DELETE
FROM "bundle_analysis_cacheconfig"
WHERE "bundle_analysis_cacheconfig"."repo_id" 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
Expand Up @@ -16,6 +16,24 @@ WHERE "reports_dailytestrollups"."repoid" IN
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)


-- CacheConfig
DELETE
FROM "bundle_analysis_cacheconfig"
WHERE "bundle_analysis_cacheconfig"."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 90bf1e2

Please sign in to comment.