Skip to content

ref: add state-only migration to reflect existing indexes in prod #91901

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

Merged
merged 1 commit into from
May 19, 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
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ remote_subscriptions: 0003_drop_remote_subscription

replays: 0005_drop_replay_index

sentry: 0902_detection_type_match_size
sentry: 0903_missing_indexes_in_state

social_auth: 0002_default_auto_field

Expand Down
4 changes: 2 additions & 2 deletions src/sentry/data_export/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ExportedData(Model):

organization = FlexibleForeignKey("sentry.Organization")
user_id = HybridCloudForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete="SET_NULL")
file_id = BoundedBigIntegerField(null=True)
file_id = BoundedBigIntegerField(null=True, db_index=True)
date_added = models.DateTimeField(default=timezone.now)
date_finished = models.DateTimeField(null=True)
date_expired = models.DateTimeField(null=True, db_index=True)
Expand Down Expand Up @@ -161,7 +161,7 @@ class ExportedDataBlob(Model):
__relocation_scope__ = RelocationScope.Excluded

data_export = FlexibleForeignKey("sentry.ExportedData")
blob_id = BoundedBigIntegerField()
blob_id = BoundedBigIntegerField(db_index=True)
offset = BoundedBigIntegerField()

class Meta:
Expand Down
69 changes: 69 additions & 0 deletions src/sentry/migrations/0903_missing_indexes_in_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Generated by Django 5.2.1 on 2025-05-19 21:17

from django.db import migrations

import sentry.db.models.fields.bounded
from sentry.new_migrations.migrations import CheckedMigration


class Migration(CheckedMigration):
# This flag is used to mark that a migration shouldn't be automatically run in production.
# This should only be used for operations where it's safe to run the migration after your
# code has deployed. So this should not be used for most operations that alter the schema
# of a table.
# Here are some things that make sense to mark as post deployment:
# - Large data migrations. Typically we want these to be run manually so that they can be
# monitored and not block the deploy for a long period of time while they run.
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
# run this outside deployments so that we don't block them. Note that while adding an index
# is a schema change, it's completely safe to run the operation after the code has deployed.
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment

is_post_deployment = False

dependencies = [
("sentry", "0902_detection_type_match_size"),
]

operations = [
migrations.SeparateDatabaseAndState(
state_operations=[
migrations.AlterField(
model_name="exporteddata",
name="file_id",
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(
db_index=True, null=True
),
),
migrations.AlterField(
model_name="exporteddatablob",
name="blob_id",
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
),
migrations.AlterField(
model_name="projectdebugfile",
name="project_id",
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(
db_index=True, null=True
),
),
migrations.AlterField(
model_name="releasefile",
name="dist_id",
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(
db_index=True, null=True
),
),
migrations.AlterField(
model_name="releasefile",
name="organization_id",
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
),
migrations.AlterField(
model_name="releasefile",
name="release_id",
field=sentry.db.models.fields.bounded.BoundedBigIntegerField(db_index=True),
),
]
)
]
2 changes: 1 addition & 1 deletion src/sentry/models/debugfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class ProjectDebugFile(Model):
checksum = models.CharField(max_length=40, null=True, db_index=True)
object_name = models.TextField()
cpu_name = models.CharField(max_length=40)
project_id = BoundedBigIntegerField(null=True)
project_id = BoundedBigIntegerField(null=True, db_index=True)
debug_id = models.CharField(max_length=64, db_column="uuid")
code_id = models.CharField(max_length=64, null=True)
data: models.Field[dict[str, Any] | None, dict[str, Any] | None] = JSONField(null=True)
Expand Down
6 changes: 3 additions & 3 deletions src/sentry/models/releasefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ class ReleaseFile(Model):

__relocation_scope__ = RelocationScope.Excluded

organization_id = BoundedBigIntegerField()
organization_id = BoundedBigIntegerField(db_index=True)
# DEPRECATED
project_id = BoundedBigIntegerField(null=True)
release_id = BoundedBigIntegerField()
release_id = BoundedBigIntegerField(db_index=True)
file = FlexibleForeignKey("sentry.File")
ident = models.CharField(max_length=40)
name = models.TextField()
dist_id = BoundedBigIntegerField(null=True)
dist_id = BoundedBigIntegerField(null=True, db_index=True)

#: For classic file uploads, this field is 1.
#: For release archives, this field is 0.
Expand Down
Loading