Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit de4b37b

Browse files
authored
Copy over some django_apps and their associated models to shared (#469)
1 parent a03c2f9 commit de4b37b

35 files changed

+1027
-1
lines changed

shared/django_apps/compare/__init__.py

Whitespace-only changes.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Generated by Django 3.1.6 on 2021-07-05 09:22
2+
3+
import uuid
4+
5+
import django.db.models.deletion
6+
from django.db import migrations, models
7+
8+
9+
class Migration(migrations.Migration):
10+
initial = True
11+
12+
dependencies = [("core", "0004_pull_user_provided_base_sha")]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name="CommitComparison",
17+
fields=[
18+
("id", models.BigAutoField(primary_key=True, serialize=False)),
19+
("external_id", models.UUIDField(default=uuid.uuid4, editable=False)),
20+
("created_at", models.DateTimeField(auto_now_add=True)),
21+
("updated_at", models.DateTimeField(auto_now=True)),
22+
(
23+
"state",
24+
models.TextField(
25+
choices=[
26+
("pending", "Pending"),
27+
("error", "Error"),
28+
("processed", "Processed"),
29+
],
30+
default="pending",
31+
),
32+
),
33+
(
34+
"report_storage_path",
35+
models.CharField(blank=True, max_length=150, null=True),
36+
),
37+
(
38+
"base_commit",
39+
models.ForeignKey(
40+
on_delete=django.db.models.deletion.CASCADE,
41+
related_name="base_commit_comparisons",
42+
to="core.commit",
43+
),
44+
),
45+
(
46+
"compare_commit",
47+
models.ForeignKey(
48+
on_delete=django.db.models.deletion.CASCADE,
49+
related_name="compare_commit_comparisons",
50+
to="core.commit",
51+
),
52+
),
53+
],
54+
),
55+
migrations.AddConstraint(
56+
model_name="commitcomparison",
57+
constraint=models.UniqueConstraint(
58+
fields=("base_commit", "compare_commit"),
59+
name="unique_comparison_between_commit",
60+
),
61+
),
62+
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Generated by Django 3.1.6 on 2021-09-02 04:42
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [("compare", "0001_initial")]
8+
9+
operations = [
10+
migrations.AddField(
11+
model_name="commitcomparison",
12+
name="patch_totals",
13+
field=models.JSONField(null=True),
14+
)
15+
]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 3.1.13 on 2021-09-23 02:43
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
dependencies = [("compare", "0002_commitcomparison_patch_totals")]
8+
9+
operations = [
10+
migrations.AddField(
11+
model_name="commitcomparison",
12+
name="error",
13+
field=models.TextField(
14+
choices=[
15+
("missing_base_report", "Missing Base Report"),
16+
("missing_head_report", "Missing Head Report"),
17+
],
18+
null=True,
19+
),
20+
)
21+
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Generated by Django 3.2.12 on 2022-07-01 00:57
2+
3+
import uuid
4+
5+
import django.db.models.deletion
6+
from django.db import migrations, models
7+
8+
9+
class Migration(migrations.Migration):
10+
dependencies = [
11+
("reports", "0003_auto_20211118_1150"),
12+
("compare", "0003_commitcomparison_error"),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name="FlagComparison",
18+
fields=[
19+
("id", models.BigAutoField(primary_key=True, serialize=False)),
20+
("external_id", models.UUIDField(default=uuid.uuid4, editable=False)),
21+
("created_at", models.DateTimeField(auto_now_add=True)),
22+
("updated_at", models.DateTimeField(auto_now=True)),
23+
("coverage_totals", models.JSONField(null=True)),
24+
("patch_totals", models.JSONField(null=True)),
25+
(
26+
"commit_comparison",
27+
models.ForeignKey(
28+
on_delete=django.db.models.deletion.CASCADE,
29+
related_name="commit_comparisons",
30+
to="compare.commitcomparison",
31+
),
32+
),
33+
(
34+
"repositoryflag",
35+
models.ForeignKey(
36+
on_delete=django.db.models.deletion.CASCADE,
37+
related_name="flag_comparisons",
38+
to="reports.repositoryflag",
39+
),
40+
),
41+
],
42+
options={
43+
"abstract": False,
44+
},
45+
),
46+
]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Generated by Django 3.2.12 on 2022-07-13 22:10
2+
3+
import django.db.models.deletion
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("compare", "0004_flagcomparison"),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name="flagcomparison",
15+
old_name="coverage_totals",
16+
new_name="head_totals",
17+
),
18+
migrations.AddField(
19+
model_name="flagcomparison",
20+
name="base_totals",
21+
field=models.JSONField(null=True),
22+
),
23+
migrations.AlterField(
24+
model_name="flagcomparison",
25+
name="commit_comparison",
26+
field=models.ForeignKey(
27+
on_delete=django.db.models.deletion.CASCADE,
28+
related_name="flag_comparisons",
29+
to="compare.commitcomparison",
30+
),
31+
),
32+
]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Generated by Django 4.1.7 on 2023-04-20 14:33
2+
3+
import uuid
4+
5+
import django.db.models.deletion
6+
from django.db import migrations, models
7+
8+
9+
class Migration(migrations.Migration):
10+
dependencies = [
11+
("compare", "0005_auto_20220713_2210"),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name="ComponentComparison",
17+
fields=[
18+
("id", models.BigAutoField(primary_key=True, serialize=False)),
19+
("external_id", models.UUIDField(default=uuid.uuid4, editable=False)),
20+
("created_at", models.DateTimeField(auto_now_add=True)),
21+
("updated_at", models.DateTimeField(auto_now=True)),
22+
("component_id", models.TextField()),
23+
("head_totals", models.JSONField(null=True)),
24+
("base_totals", models.JSONField(null=True)),
25+
("patch_totals", models.JSONField(null=True)),
26+
(
27+
"commit_comparison",
28+
models.ForeignKey(
29+
on_delete=django.db.models.deletion.CASCADE,
30+
related_name="component_comparisons",
31+
to="compare.commitcomparison",
32+
),
33+
),
34+
],
35+
),
36+
migrations.AddIndex(
37+
model_name="componentcomparison",
38+
index=models.Index(
39+
fields=["commit_comparison_id", "component_id"],
40+
name="component_comparison_component",
41+
),
42+
),
43+
]

shared/django_apps/compare/migrations/__init__.py

Whitespace-only changes.

shared/django_apps/compare/models.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
from django.db import models
2+
from django_prometheus.models import ExportModelOperationsMixin
3+
4+
from shared.django_apps.codecov.models import BaseCodecovModel
5+
from shared.django_apps.core.models import Commit
6+
from shared.django_apps.reports.models import RepositoryFlag
7+
8+
# Added to avoid 'doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS' error\
9+
# Needs to be called the same as the API app
10+
COMPARE_APP_LABEL = "compare"
11+
12+
13+
class CommitComparison(
14+
ExportModelOperationsMixin("compare.commit_comparison"), BaseCodecovModel
15+
):
16+
class CommitComparisonStates(models.TextChoices):
17+
PENDING = "pending"
18+
ERROR = "error"
19+
PROCESSED = "processed"
20+
21+
class CommitComparisonErrors(models.TextChoices):
22+
MISSING_BASE_REPORT = "missing_base_report"
23+
MISSING_HEAD_REPORT = "missing_head_report"
24+
25+
base_commit = models.ForeignKey(
26+
Commit, on_delete=models.CASCADE, related_name="base_commit_comparisons"
27+
)
28+
compare_commit = models.ForeignKey(
29+
Commit, on_delete=models.CASCADE, related_name="compare_commit_comparisons"
30+
)
31+
state = models.TextField(
32+
choices=CommitComparisonStates.choices, default=CommitComparisonStates.PENDING
33+
)
34+
error = models.TextField(choices=CommitComparisonErrors.choices, null=True)
35+
report_storage_path = models.CharField(max_length=150, null=True, blank=True)
36+
patch_totals = models.JSONField(null=True)
37+
38+
class Meta:
39+
app_label = COMPARE_APP_LABEL
40+
db_table = "compare_commitcomparison"
41+
42+
constraints = [
43+
models.UniqueConstraint(
44+
name="unique_comparison_between_commit",
45+
fields=["base_commit", "compare_commit"],
46+
)
47+
]
48+
49+
@property
50+
def is_processed(self):
51+
return self.state == CommitComparison.CommitComparisonStates.PROCESSED
52+
53+
54+
class FlagComparison(
55+
ExportModelOperationsMixin("compare.flag_comparison"), BaseCodecovModel
56+
):
57+
commit_comparison = models.ForeignKey(
58+
CommitComparison, on_delete=models.CASCADE, related_name="flag_comparisons"
59+
)
60+
repositoryflag = models.ForeignKey(
61+
RepositoryFlag, on_delete=models.CASCADE, related_name="flag_comparisons"
62+
)
63+
head_totals = models.JSONField(null=True)
64+
base_totals = models.JSONField(null=True)
65+
patch_totals = models.JSONField(null=True)
66+
67+
class Meta:
68+
app_label = COMPARE_APP_LABEL
69+
db_table = "compare_flagcomparison"
70+
71+
72+
class ComponentComparison(
73+
ExportModelOperationsMixin("compare.component_comparison"), BaseCodecovModel
74+
):
75+
commit_comparison = models.ForeignKey(
76+
CommitComparison, on_delete=models.CASCADE, related_name="component_comparisons"
77+
)
78+
component_id = models.TextField(null=False, blank=False)
79+
head_totals = models.JSONField(null=True)
80+
base_totals = models.JSONField(null=True)
81+
patch_totals = models.JSONField(null=True)
82+
83+
class Meta:
84+
app_label = COMPARE_APP_LABEL
85+
db_table = "compare_componentcomparison"
86+
87+
indexes = [
88+
models.Index(
89+
fields=["commit_comparison_id", "component_id"],
90+
name="component_comparison_component",
91+
),
92+
]

shared/django_apps/compare/tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)