Skip to content

Commit b1c3ebb

Browse files
committed
PR feedback
1 parent f6fd39c commit b1c3ebb

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

src/sentry/migrations/0909_emerge_upload_models.py renamed to src/sentry/preprod/migrations/0001_emerge_upload_models.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# Generated by Django 5.2.1 on 2025-05-21 22:48
1+
# Generated by Django 5.2.1 on 2025-05-27 18:53
22

33
import django.db.models.deletion
44
from django.db import migrations, models
55

66
import sentry.db.models.fields.bounded
77
import sentry.db.models.fields.foreignkey
88
import sentry.db.models.fields.jsonfield
9+
import sentry.preprod.models
910
from sentry.new_migrations.migrations import CheckedMigration
1011

1112

@@ -24,8 +25,10 @@ class Migration(CheckedMigration):
2425

2526
is_post_deployment = False
2627

28+
initial = True
29+
2730
dependencies = [
28-
("sentry", "0908_increase_email_field_length"),
31+
("sentry", "0913_split_discover_dataset_dashboards_self_hosted"),
2932
]
3033

3134
operations = [
@@ -40,10 +43,6 @@ class Migration(CheckedMigration):
4043
),
4144
("date_updated", models.DateTimeField(auto_now=True)),
4245
("date_added", models.DateTimeField(auto_now_add=True)),
43-
(
44-
"organization_id",
45-
sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
46-
),
4746
("name", models.CharField(max_length=255)),
4847
(
4948
"project",
@@ -68,12 +67,13 @@ class Migration(CheckedMigration):
6867
),
6968
("date_updated", models.DateTimeField(auto_now=True)),
7069
("date_added", models.DateTimeField(auto_now_add=True)),
70+
("date_built", models.DateTimeField(null=True)),
7171
(
72-
"organization_id",
73-
sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
72+
"state",
73+
sentry.db.models.fields.bounded.BoundedPositiveIntegerField(
74+
default=sentry.preprod.models.PreprodArtifact.ArtifactState["UPLOADING"]
75+
),
7476
),
75-
("date_built", models.DateTimeField(null=True)),
76-
("state", sentry.db.models.fields.bounded.BoundedPositiveIntegerField(default=0)),
7777
(
7878
"artifact_type",
7979
sentry.db.models.fields.bounded.BoundedPositiveIntegerField(null=True),
@@ -85,8 +85,7 @@ class Migration(CheckedMigration):
8585
("error_message", models.TextField(null=True)),
8686
("build_version", models.CharField(max_length=255, null=True)),
8787
("build_number", sentry.db.models.fields.bounded.BoundedBigIntegerField(null=True)),
88-
("build_uuid", models.UUIDField(null=True)),
89-
("misc", sentry.db.models.fields.jsonfield.JSONField(null=True)),
88+
("extras", sentry.db.models.fields.jsonfield.JSONField(null=True)),
9089
(
9190
"file",
9291
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
@@ -104,7 +103,7 @@ class Migration(CheckedMigration):
104103
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
105104
null=True,
106105
on_delete=django.db.models.deletion.SET_NULL,
107-
to="sentry.preprodbuildconfiguration",
106+
to="preprod.preprodbuildconfiguration",
108107
),
109108
),
110109
],
@@ -127,7 +126,14 @@ class Migration(CheckedMigration):
127126
"metrics_artifact_type",
128127
sentry.db.models.fields.bounded.BoundedPositiveIntegerField(null=True),
129128
),
130-
("state", sentry.db.models.fields.bounded.BoundedPositiveIntegerField(default=0)),
129+
(
130+
"state",
131+
sentry.db.models.fields.bounded.BoundedPositiveIntegerField(
132+
default=sentry.preprod.models.PreprodArtifactSizeMetrics.SizeAnalysisState[
133+
"PENDING"
134+
]
135+
),
136+
),
131137
(
132138
"error_code",
133139
sentry.db.models.fields.bounded.BoundedPositiveIntegerField(null=True),
@@ -153,7 +159,7 @@ class Migration(CheckedMigration):
153159
(
154160
"preprod_artifact",
155161
sentry.db.models.fields.foreignkey.FlexibleForeignKey(
156-
on_delete=django.db.models.deletion.CASCADE, to="sentry.preprodartifact"
162+
on_delete=django.db.models.deletion.CASCADE, to="preprod.preprodartifact"
157163
),
158164
),
159165
],

src/sentry/preprod/migrations/__init__.py

Whitespace-only changes.

src/sentry/preprod/models.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from enum import IntEnum
12
from typing import Any
23

34
from django.db import models
@@ -16,7 +17,7 @@
1617
@region_silo_model
1718
class PreprodArtifact(DefaultFieldsModel):
1819
"""
19-
A pre-production artifact provided by the user, presumably from their CI/CD pipeline.
20+
A pre-production artifact provided by the user, presumably from their CI/CD pipeline or a manual build.
2021
With this, we can analyze their artifact and provide them with insights to fix _before_
2122
it's released to production.
2223
@@ -25,7 +26,7 @@ class PreprodArtifact(DefaultFieldsModel):
2526
- Android app builds
2627
"""
2728

28-
class ArtifactState:
29+
class ArtifactState(IntEnum):
2930
UPLOADING = 0
3031
"""The user has initiated the upload, but it is not yet complete."""
3132
UPLOADED = 1
@@ -44,7 +45,7 @@ def as_choices(cls):
4445
(cls.FAILED, "failed"),
4546
)
4647

47-
class ArtifactType:
48+
class ArtifactType(IntEnum):
4849
XCARCHIVE = 0
4950
"""Apple Xcode archive."""
5051
AAB = 1
@@ -60,7 +61,7 @@ def as_choices(cls):
6061
(cls.APK, "apk"),
6162
)
6263

63-
class ErrorCode:
64+
class ErrorCode(IntEnum):
6465
UNKNOWN = 0
6566
"""The error code is unknown. Try to use a descriptive error code if possible."""
6667
UPLOAD_TIMEOUT = 1
@@ -81,8 +82,6 @@ def as_choices(cls):
8182

8283
__relocation_scope__ = RelocationScope.Excluded
8384

84-
# Having a FK to both Org/Project is unnecessary
85-
organization_id = BoundedBigIntegerField(db_index=True)
8685
project = FlexibleForeignKey("sentry.Project")
8786

8887
# Nullable in case the file upload fails
@@ -93,13 +92,14 @@ def as_choices(cls):
9392
date_built = models.DateTimeField(null=True)
9493

9594
build_configuration = FlexibleForeignKey(
96-
"sentry.PreprodBuildConfiguration", null=True, on_delete=models.SET_NULL
95+
"preprod.PreprodBuildConfiguration", null=True, on_delete=models.SET_NULL
9796
)
9897

9998
state = BoundedPositiveIntegerField(
10099
default=ArtifactState.UPLOADING, choices=ArtifactState.as_choices()
101100
)
102101

102+
# Nullable because we only know the type after the artifact has been processed
103103
artifact_type = BoundedPositiveIntegerField(choices=ArtifactType.as_choices(), null=True)
104104

105105
error_code = BoundedPositiveIntegerField(choices=ErrorCode.as_choices(), null=True)
@@ -110,10 +110,10 @@ def as_choices(cls):
110110
# E.g. 9999
111111
build_number = BoundedBigIntegerField(null=True)
112112

113-
misc: models.Field[dict[str, Any], dict[str, Any]] = JSONField(null=True)
113+
extras: models.Field[dict[str, Any], dict[str, Any]] = JSONField(null=True)
114114

115115
class Meta:
116-
app_label = "sentry"
116+
app_label = "preprod"
117117
db_table = "sentry_preprodartifact"
118118

119119

@@ -123,12 +123,11 @@ class PreprodBuildConfiguration(DefaultFieldsModel):
123123

124124
__relocation_scope__ = RelocationScope.Excluded
125125

126-
organization_id = BoundedBigIntegerField(db_index=True)
127126
project = FlexibleForeignKey("sentry.Project")
128127
name = models.CharField(max_length=255)
129128

130129
class Meta:
131-
app_label = "sentry"
130+
app_label = "preprod"
132131
db_table = "sentry_preprodbuildconfiguration"
133132
unique_together = ("project", "name")
134133

@@ -140,7 +139,7 @@ class PreprodArtifactSizeMetrics(DefaultFieldsModel):
140139
size metrics.
141140
"""
142141

143-
class MetricsArtifactType:
142+
class MetricsArtifactType(IntEnum):
144143
MAIN_ARTIFACT = 0
145144
"""The main artifact."""
146145
WATCH_ARTIFACT = 1
@@ -156,7 +155,7 @@ def as_choices(cls):
156155
(cls.ANDROID_DYNAMIC_FEATURE, "android_dynamic_feature_artifact"),
157156
)
158157

159-
class SizeAnalysisState:
158+
class SizeAnalysisState(IntEnum):
160159
PENDING = 0
161160
"""Size analysis has not started yet."""
162161
PROCESSING = 1
@@ -175,7 +174,7 @@ def as_choices(cls):
175174
(cls.FAILED, "failed"),
176175
)
177176

178-
class ErrorCode:
177+
class ErrorCode(IntEnum):
179178
UNKNOWN = 0
180179
"""The error code is unknown. Try to use a descriptive error code if possible."""
181180
TIMEOUT = 1
@@ -196,7 +195,7 @@ def as_choices(cls):
196195

197196
__relocation_scope__ = RelocationScope.Excluded
198197

199-
preprod_artifact = FlexibleForeignKey("sentry.PreprodArtifact")
198+
preprod_artifact = FlexibleForeignKey("preprod.PreprodArtifact")
200199
metrics_artifact_type = BoundedPositiveIntegerField(
201200
choices=MetricsArtifactType.as_choices(), null=True
202201
)
@@ -218,6 +217,6 @@ def as_choices(cls):
218217
max_download_size = BoundedPositiveBigIntegerField(null=True)
219218

220219
class Meta:
221-
app_label = "sentry"
220+
app_label = "preprod"
222221
db_table = "sentry_preprodartifactsizemetrics"
223222
unique_together = ("preprod_artifact", "metrics_artifact_type")

0 commit comments

Comments
 (0)