Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy over some django_apps and their associated models to shared #469

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
62 changes: 62 additions & 0 deletions shared/django_apps/compare/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Generated by Django 3.1.6 on 2021-07-05 09:22

import uuid

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
initial = True

dependencies = [("core", "0004_pull_user_provided_base_sha")]

operations = [
migrations.CreateModel(
name="CommitComparison",
fields=[
("id", models.BigAutoField(primary_key=True, serialize=False)),
("external_id", models.UUIDField(default=uuid.uuid4, editable=False)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"state",
models.TextField(
choices=[
("pending", "Pending"),
("error", "Error"),
("processed", "Processed"),
],
default="pending",
),
),
(
"report_storage_path",
models.CharField(blank=True, max_length=150, null=True),
),
(
"base_commit",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="base_commit_comparisons",
to="core.commit",
),
),
(
"compare_commit",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="compare_commit_comparisons",
to="core.commit",
),
),
],
),
migrations.AddConstraint(
model_name="commitcomparison",
constraint=models.UniqueConstraint(
fields=("base_commit", "compare_commit"),
name="unique_comparison_between_commit",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Generated by Django 3.1.6 on 2021-09-02 04:42

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [("compare", "0001_initial")]

operations = [
migrations.AddField(
model_name="commitcomparison",
name="patch_totals",
field=models.JSONField(null=True),
)
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.1.13 on 2021-09-23 02:43

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [("compare", "0002_commitcomparison_patch_totals")]

operations = [
migrations.AddField(
model_name="commitcomparison",
name="error",
field=models.TextField(
choices=[
("missing_base_report", "Missing Base Report"),
("missing_head_report", "Missing Head Report"),
],
null=True,
),
)
]
46 changes: 46 additions & 0 deletions shared/django_apps/compare/migrations/0004_flagcomparison.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 3.2.12 on 2022-07-01 00:57

import uuid

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("reports", "0003_auto_20211118_1150"),
("compare", "0003_commitcomparison_error"),
]

operations = [
migrations.CreateModel(
name="FlagComparison",
fields=[
("id", models.BigAutoField(primary_key=True, serialize=False)),
("external_id", models.UUIDField(default=uuid.uuid4, editable=False)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("coverage_totals", models.JSONField(null=True)),
("patch_totals", models.JSONField(null=True)),
(
"commit_comparison",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="commit_comparisons",
to="compare.commitcomparison",
),
),
(
"repositoryflag",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="flag_comparisons",
to="reports.repositoryflag",
),
),
],
options={
"abstract": False,
},
),
]
32 changes: 32 additions & 0 deletions shared/django_apps/compare/migrations/0005_auto_20220713_2210.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 3.2.12 on 2022-07-13 22:10

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("compare", "0004_flagcomparison"),
]

operations = [
migrations.RenameField(
model_name="flagcomparison",
old_name="coverage_totals",
new_name="head_totals",
),
migrations.AddField(
model_name="flagcomparison",
name="base_totals",
field=models.JSONField(null=True),
),
migrations.AlterField(
model_name="flagcomparison",
name="commit_comparison",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="flag_comparisons",
to="compare.commitcomparison",
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.1.7 on 2023-04-20 14:33

import uuid

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("compare", "0005_auto_20220713_2210"),
]

operations = [
migrations.CreateModel(
name="ComponentComparison",
fields=[
("id", models.BigAutoField(primary_key=True, serialize=False)),
("external_id", models.UUIDField(default=uuid.uuid4, editable=False)),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("component_id", models.TextField()),
("head_totals", models.JSONField(null=True)),
("base_totals", models.JSONField(null=True)),
("patch_totals", models.JSONField(null=True)),
(
"commit_comparison",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="component_comparisons",
to="compare.commitcomparison",
),
),
],
),
migrations.AddIndex(
model_name="componentcomparison",
index=models.Index(
fields=["commit_comparison_id", "component_id"],
name="component_comparison_component",
),
),
]
Empty file.
92 changes: 92 additions & 0 deletions shared/django_apps/compare/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from django.db import models
from django_prometheus.models import ExportModelOperationsMixin

from shared.django_apps.codecov.models import BaseCodecovModel
from shared.django_apps.core.models import Commit
from shared.django_apps.reports.models import RepositoryFlag

# Added to avoid 'doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS' error\
# Needs to be called the same as the API app
COMPARE_APP_LABEL = "compare"


class CommitComparison(
ExportModelOperationsMixin("compare.commit_comparison"), BaseCodecovModel
):
class CommitComparisonStates(models.TextChoices):
PENDING = "pending"
ERROR = "error"
PROCESSED = "processed"

class CommitComparisonErrors(models.TextChoices):
MISSING_BASE_REPORT = "missing_base_report"
MISSING_HEAD_REPORT = "missing_head_report"

base_commit = models.ForeignKey(
Commit, on_delete=models.CASCADE, related_name="base_commit_comparisons"
)
compare_commit = models.ForeignKey(
Commit, on_delete=models.CASCADE, related_name="compare_commit_comparisons"
)
state = models.TextField(
choices=CommitComparisonStates.choices, default=CommitComparisonStates.PENDING
)
error = models.TextField(choices=CommitComparisonErrors.choices, null=True)
report_storage_path = models.CharField(max_length=150, null=True, blank=True)
patch_totals = models.JSONField(null=True)

class Meta:
app_label = COMPARE_APP_LABEL
db_table = "compare_commitcomparison"

constraints = [
models.UniqueConstraint(
name="unique_comparison_between_commit",
fields=["base_commit", "compare_commit"],
)
]

@property
def is_processed(self):
return self.state == CommitComparison.CommitComparisonStates.PROCESSED


class FlagComparison(
ExportModelOperationsMixin("compare.flag_comparison"), BaseCodecovModel
):
commit_comparison = models.ForeignKey(
CommitComparison, on_delete=models.CASCADE, related_name="flag_comparisons"
)
repositoryflag = models.ForeignKey(
RepositoryFlag, on_delete=models.CASCADE, related_name="flag_comparisons"
)
head_totals = models.JSONField(null=True)
base_totals = models.JSONField(null=True)
patch_totals = models.JSONField(null=True)

class Meta:
app_label = COMPARE_APP_LABEL
db_table = "compare_flagcomparison"


class ComponentComparison(
ExportModelOperationsMixin("compare.component_comparison"), BaseCodecovModel
):
commit_comparison = models.ForeignKey(
CommitComparison, on_delete=models.CASCADE, related_name="component_comparisons"
)
component_id = models.TextField(null=False, blank=False)
head_totals = models.JSONField(null=True)
base_totals = models.JSONField(null=True)
patch_totals = models.JSONField(null=True)

class Meta:
app_label = COMPARE_APP_LABEL
db_table = "compare_componentcomparison"

indexes = [
models.Index(
fields=["commit_comparison_id", "component_id"],
name="component_comparison_component",
),
]
Empty file.
Loading
Loading