Skip to content

Commit 669be66

Browse files
ref: represent organization slug upper index in code (#91879)
<!-- Describe your PR here. -->
1 parent fbc6095 commit 669be66

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
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: 0898_groupedmessage_wrong_int_type
24+
sentry: 0899_organization_slug_upper_idx
2525

2626
social_auth: 0002_default_auto_field
2727

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Generated by Django 5.2.1 on 2025-05-19 17:18
2+
3+
import django.db.models.functions.text
4+
from django.db import migrations, models
5+
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", "0898_groupedmessage_wrong_int_type"),
26+
]
27+
28+
operations = [
29+
migrations.SeparateDatabaseAndState(
30+
state_operations=[
31+
migrations.AddIndex(
32+
model_name="organization",
33+
index=models.Index(
34+
django.db.models.functions.text.Upper("slug"),
35+
name="organization_slug_upper_idx",
36+
),
37+
),
38+
]
39+
)
40+
]

src/sentry/models/organization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from django.conf import settings
88
from django.db import models, router, transaction
9+
from django.db.models.functions.text import Upper
910
from django.urls import NoReverseMatch, reverse
1011
from django.utils import timezone
1112
from django.utils.functional import cached_property
@@ -208,8 +209,7 @@ class flags(TypedClassBitField):
208209
class Meta:
209210
app_label = "sentry"
210211
db_table = "sentry_organization"
211-
# TODO: Once we're on a version of Django that supports functional indexes,
212-
# include index on `upper((slug::text))` here.
212+
indexes = (models.Index(Upper("slug"), name="organization_slug_upper_idx"),)
213213

214214
__repr__ = sane_repr("owner_id", "name", "slug")
215215

0 commit comments

Comments
 (0)