Skip to content

Commit ad8f1ae

Browse files
ref: add state-only migration to reflect existing indexes in prod (#91901)
when these were converted from PKEY to int columns the indexes were left but the state did not reflect that <!-- Describe your PR here. -->
1 parent 626ec37 commit ad8f1ae

File tree

5 files changed

+76
-7
lines changed

5 files changed

+76
-7
lines changed

migrations_lockfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ remote_subscriptions: 0003_drop_remote_subscription
2121

2222
replays: 0005_drop_replay_index
2323

24-
sentry: 0902_detection_type_match_size
24+
sentry: 0903_missing_indexes_in_state
2525

2626
social_auth: 0002_default_auto_field
2727

src/sentry/data_export/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ExportedData(Model):
3737

3838
organization = FlexibleForeignKey("sentry.Organization")
3939
user_id = HybridCloudForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete="SET_NULL")
40-
file_id = BoundedBigIntegerField(null=True)
40+
file_id = BoundedBigIntegerField(null=True, db_index=True)
4141
date_added = models.DateTimeField(default=timezone.now)
4242
date_finished = models.DateTimeField(null=True)
4343
date_expired = models.DateTimeField(null=True, db_index=True)
@@ -161,7 +161,7 @@ class ExportedDataBlob(Model):
161161
__relocation_scope__ = RelocationScope.Excluded
162162

163163
data_export = FlexibleForeignKey("sentry.ExportedData")
164-
blob_id = BoundedBigIntegerField()
164+
blob_id = BoundedBigIntegerField(db_index=True)
165165
offset = BoundedBigIntegerField()
166166

167167
class Meta:
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Generated by Django 5.2.1 on 2025-05-19 21:17
2+
3+
from django.db import migrations
4+
5+
import sentry.db.models.fields.bounded
6+
from sentry.new_migrations.migrations import CheckedMigration
7+
8+
9+
class Migration(CheckedMigration):
10+
# This flag is used to mark that a migration shouldn't be automatically run in production.
11+
# This should only be used for operations where it's safe to run the migration after your
12+
# code has deployed. So this should not be used for most operations that alter the schema
13+
# of a table.
14+
# Here are some things that make sense to mark as post deployment:
15+
# - Large data migrations. Typically we want these to be run manually so that they can be
16+
# monitored and not block the deploy for a long period of time while they run.
17+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
18+
# run this outside deployments so that we don't block them. Note that while adding an index
19+
# is a schema change, it's completely safe to run the operation after the code has deployed.
20+
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
21+
22+
is_post_deployment = False
23+
24+
dependencies = [
25+
("sentry", "0902_detection_type_match_size"),
26+
]
27+
28+
operations = [
29+
migrations.SeparateDatabaseAndState(
30+
state_operations=[
31+
migrations.AlterField(
32+
model_name="exporteddata",
33+
name="file_id",
34+
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(
35+
db_index=True, null=True
36+
),
37+
),
38+
migrations.AlterField(
39+
model_name="exporteddatablob",
40+
name="blob_id",
41+
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
42+
),
43+
migrations.AlterField(
44+
model_name="projectdebugfile",
45+
name="project_id",
46+
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(
47+
db_index=True, null=True
48+
),
49+
),
50+
migrations.AlterField(
51+
model_name="releasefile",
52+
name="dist_id",
53+
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(
54+
db_index=True, null=True
55+
),
56+
),
57+
migrations.AlterField(
58+
model_name="releasefile",
59+
name="organization_id",
60+
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
61+
),
62+
migrations.AlterField(
63+
model_name="releasefile",
64+
name="release_id",
65+
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
66+
),
67+
]
68+
)
69+
]

src/sentry/models/debugfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class ProjectDebugFile(Model):
127127
checksum = models.CharField(max_length=40, null=True, db_index=True)
128128
object_name = models.TextField()
129129
cpu_name = models.CharField(max_length=40)
130-
project_id = BoundedBigIntegerField(null=True)
130+
project_id = BoundedBigIntegerField(null=True, db_index=True)
131131
debug_id = models.CharField(max_length=64, db_column="uuid")
132132
code_id = models.CharField(max_length=64, null=True)
133133
data: models.Field[dict[str, Any] | None, dict[str, Any] | None] = JSONField(null=True)

src/sentry/models/releasefile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ class ReleaseFile(Model):
7070

7171
__relocation_scope__ = RelocationScope.Excluded
7272

73-
organization_id = BoundedBigIntegerField()
73+
organization_id = BoundedBigIntegerField(db_index=True)
7474
# DEPRECATED
7575
project_id = BoundedBigIntegerField(null=True)
76-
release_id = BoundedBigIntegerField()
76+
release_id = BoundedBigIntegerField(db_index=True)
7777
file = FlexibleForeignKey("sentry.File")
7878
ident = models.CharField(max_length=40)
7979
name = models.TextField()
80-
dist_id = BoundedBigIntegerField(null=True)
80+
dist_id = BoundedBigIntegerField(null=True, db_index=True)
8181

8282
#: For classic file uploads, this field is 1.
8383
#: For release archives, this field is 0.

0 commit comments

Comments
 (0)