1
+ from enum import IntEnum
1
2
from typing import Any
2
3
3
4
from django .db import models
16
17
@region_silo_model
17
18
class PreprodArtifact (DefaultFieldsModel ):
18
19
"""
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 .
20
21
With this, we can analyze their artifact and provide them with insights to fix _before_
21
22
it's released to production.
22
23
@@ -25,7 +26,7 @@ class PreprodArtifact(DefaultFieldsModel):
25
26
- Android app builds
26
27
"""
27
28
28
- class ArtifactState :
29
+ class ArtifactState ( IntEnum ) :
29
30
UPLOADING = 0
30
31
"""The user has initiated the upload, but it is not yet complete."""
31
32
UPLOADED = 1
@@ -44,7 +45,7 @@ def as_choices(cls):
44
45
(cls .FAILED , "failed" ),
45
46
)
46
47
47
- class ArtifactType :
48
+ class ArtifactType ( IntEnum ) :
48
49
XCARCHIVE = 0
49
50
"""Apple Xcode archive."""
50
51
AAB = 1
@@ -60,7 +61,7 @@ def as_choices(cls):
60
61
(cls .APK , "apk" ),
61
62
)
62
63
63
- class ErrorCode :
64
+ class ErrorCode ( IntEnum ) :
64
65
UNKNOWN = 0
65
66
"""The error code is unknown. Try to use a descriptive error code if possible."""
66
67
UPLOAD_TIMEOUT = 1
@@ -81,8 +82,6 @@ def as_choices(cls):
81
82
82
83
__relocation_scope__ = RelocationScope .Excluded
83
84
84
- # Having a FK to both Org/Project is unnecessary
85
- organization_id = BoundedBigIntegerField (db_index = True )
86
85
project = FlexibleForeignKey ("sentry.Project" )
87
86
88
87
# Nullable in case the file upload fails
@@ -93,13 +92,14 @@ def as_choices(cls):
93
92
date_built = models .DateTimeField (null = True )
94
93
95
94
build_configuration = FlexibleForeignKey (
96
- "sentry .PreprodBuildConfiguration" , null = True , on_delete = models .SET_NULL
95
+ "preprod .PreprodBuildConfiguration" , null = True , on_delete = models .SET_NULL
97
96
)
98
97
99
98
state = BoundedPositiveIntegerField (
100
99
default = ArtifactState .UPLOADING , choices = ArtifactState .as_choices ()
101
100
)
102
101
102
+ # Nullable because we only know the type after the artifact has been processed
103
103
artifact_type = BoundedPositiveIntegerField (choices = ArtifactType .as_choices (), null = True )
104
104
105
105
error_code = BoundedPositiveIntegerField (choices = ErrorCode .as_choices (), null = True )
@@ -110,10 +110,10 @@ def as_choices(cls):
110
110
# E.g. 9999
111
111
build_number = BoundedBigIntegerField (null = True )
112
112
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 )
114
114
115
115
class Meta :
116
- app_label = "sentry "
116
+ app_label = "preprod "
117
117
db_table = "sentry_preprodartifact"
118
118
119
119
@@ -123,12 +123,11 @@ class PreprodBuildConfiguration(DefaultFieldsModel):
123
123
124
124
__relocation_scope__ = RelocationScope .Excluded
125
125
126
- organization_id = BoundedBigIntegerField (db_index = True )
127
126
project = FlexibleForeignKey ("sentry.Project" )
128
127
name = models .CharField (max_length = 255 )
129
128
130
129
class Meta :
131
- app_label = "sentry "
130
+ app_label = "preprod "
132
131
db_table = "sentry_preprodbuildconfiguration"
133
132
unique_together = ("project" , "name" )
134
133
@@ -140,7 +139,7 @@ class PreprodArtifactSizeMetrics(DefaultFieldsModel):
140
139
size metrics.
141
140
"""
142
141
143
- class MetricsArtifactType :
142
+ class MetricsArtifactType ( IntEnum ) :
144
143
MAIN_ARTIFACT = 0
145
144
"""The main artifact."""
146
145
WATCH_ARTIFACT = 1
@@ -156,7 +155,7 @@ def as_choices(cls):
156
155
(cls .ANDROID_DYNAMIC_FEATURE , "android_dynamic_feature_artifact" ),
157
156
)
158
157
159
- class SizeAnalysisState :
158
+ class SizeAnalysisState ( IntEnum ) :
160
159
PENDING = 0
161
160
"""Size analysis has not started yet."""
162
161
PROCESSING = 1
@@ -175,7 +174,7 @@ def as_choices(cls):
175
174
(cls .FAILED , "failed" ),
176
175
)
177
176
178
- class ErrorCode :
177
+ class ErrorCode ( IntEnum ) :
179
178
UNKNOWN = 0
180
179
"""The error code is unknown. Try to use a descriptive error code if possible."""
181
180
TIMEOUT = 1
@@ -196,7 +195,7 @@ def as_choices(cls):
196
195
197
196
__relocation_scope__ = RelocationScope .Excluded
198
197
199
- preprod_artifact = FlexibleForeignKey ("sentry .PreprodArtifact" )
198
+ preprod_artifact = FlexibleForeignKey ("preprod .PreprodArtifact" )
200
199
metrics_artifact_type = BoundedPositiveIntegerField (
201
200
choices = MetricsArtifactType .as_choices (), null = True
202
201
)
@@ -218,6 +217,6 @@ def as_choices(cls):
218
217
max_download_size = BoundedPositiveBigIntegerField (null = True )
219
218
220
219
class Meta :
221
- app_label = "sentry "
220
+ app_label = "preprod "
222
221
db_table = "sentry_preprodartifactsizemetrics"
223
222
unique_together = ("preprod_artifact" , "metrics_artifact_type" )
0 commit comments