Skip to content

Commit 238ae97

Browse files
ref: use django ArrayField for sentry.users.models.* (#92062)
<!-- Describe your PR here. -->
1 parent 7f0a4df commit 238ae97

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

migrations_lockfile.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ nodestore: 0001_squashed_0002_nodestore_no_dictfield
2121

2222
replays: 0001_squashed_0005_drop_replay_index
2323

24-
sentry: 0905_fix_workflow_engine_cycle
24+
sentry: 0906_django_arrayfield_users
2525

2626
social_auth: 0001_squashed_0002_default_auto_field
2727

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Generated by Django 5.2.1 on 2025-05-21 20:20
2+
3+
import django.contrib.postgres.fields
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 = True
23+
24+
dependencies = [
25+
("sentry", "0905_fix_workflow_engine_cycle"),
26+
]
27+
28+
operations = [
29+
migrations.AlterField(
30+
model_name="identity",
31+
name="scopes",
32+
field=django.contrib.postgres.fields.ArrayField(
33+
base_field=models.TextField(), default=list, size=None
34+
),
35+
),
36+
migrations.AlterField(
37+
model_name="userrole",
38+
name="permissions",
39+
field=django.contrib.postgres.fields.ArrayField(
40+
base_field=models.TextField(), default=list, size=None
41+
),
42+
),
43+
]

src/sentry/users/models/identity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
from typing import TYPE_CHECKING, Any, ClassVar
66

77
from django.conf import settings
8+
from django.contrib.postgres.fields.array import ArrayField
89
from django.db import IntegrityError, models
910
from django.db.models import Q, QuerySet
1011
from django.utils import timezone
1112

1213
from sentry import analytics
1314
from sentry.backup.scopes import RelocationScope
1415
from sentry.db.models import (
15-
ArrayField,
1616
BoundedPositiveIntegerField,
1717
FlexibleForeignKey,
1818
Model,
@@ -199,7 +199,7 @@ class Identity(Model):
199199
external_id = models.TextField()
200200
data: models.Field[dict[str, Any], dict[str, Any]] = JSONField()
201201
status = BoundedPositiveIntegerField(default=IdentityStatus.UNKNOWN)
202-
scopes = ArrayField()
202+
scopes = ArrayField(models.TextField(), default=list)
203203
date_verified = models.DateTimeField(default=timezone.now)
204204
date_added = models.DateTimeField(default=timezone.now)
205205

src/sentry/users/models/userrole.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from __future__ import annotations
22

3-
from collections.abc import Sequence
43
from typing import Any
54

65
from django.conf import settings
6+
from django.contrib.postgres.fields.array import ArrayField
77
from django.db import models
88
from django.utils import timezone
99

1010
from sentry.backup.mixins import OverwritableConfigMixin
1111
from sentry.backup.scopes import RelocationScope
12-
from sentry.db.models import ArrayField, control_silo_model, sane_repr
12+
from sentry.db.models import control_silo_model, sane_repr
1313
from sentry.db.models.fields.foreignkey import FlexibleForeignKey
1414
from sentry.hybridcloud.models.outbox import ControlOutboxBase
1515
from sentry.hybridcloud.outbox.base import ControlOutboxProducingModel
@@ -34,7 +34,7 @@ class UserRole(OverwritableConfigMixin, ControlOutboxProducingModel):
3434
date_added = models.DateTimeField(default=timezone.now, null=True)
3535

3636
name = models.CharField(max_length=MAX_USER_ROLE_NAME_LENGTH, unique=True)
37-
permissions: models.Field[Sequence[str], list[str]] = ArrayField()
37+
permissions = ArrayField(models.TextField(), default=list)
3838
users = models.ManyToManyField("sentry.User", through="sentry.UserRoleUser")
3939

4040
class Meta:

0 commit comments

Comments
 (0)