Skip to content

Commit c06312d

Browse files
authored
chore(alerts): Remove incidentseen and incidentsubscription models (#81605)
Another follow up to #81522 to remove the unused models. A final PR will follow to drop the tables.
1 parent 5d8bd6c commit c06312d

File tree

11 files changed

+81
-131
lines changed

11 files changed

+81
-131
lines changed

fixtures/backup/model_dependencies/detailed.json

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,34 +3045,6 @@
30453045
]
30463046
]
30473047
},
3048-
"sentry.incidentseen": {
3049-
"dangling": false,
3050-
"foreign_keys": {
3051-
"incident": {
3052-
"kind": "FlexibleForeignKey",
3053-
"model": "sentry.incident",
3054-
"nullable": false
3055-
},
3056-
"user_id": {
3057-
"kind": "HybridCloudForeignKey",
3058-
"model": "sentry.user",
3059-
"nullable": false
3060-
}
3061-
},
3062-
"model": "sentry.incidentseen",
3063-
"relocation_dependencies": [],
3064-
"relocation_scope": "Excluded",
3065-
"silos": [
3066-
"Region"
3067-
],
3068-
"table_name": "sentry_incidentseen",
3069-
"uniques": [
3070-
[
3071-
"incident",
3072-
"user_id"
3073-
]
3074-
]
3075-
},
30763048
"sentry.incidentsnapshot": {
30773049
"dangling": false,
30783050
"foreign_keys": {
@@ -3100,34 +3072,6 @@
31003072
]
31013073
]
31023074
},
3103-
"sentry.incidentsubscription": {
3104-
"dangling": false,
3105-
"foreign_keys": {
3106-
"incident": {
3107-
"kind": "FlexibleForeignKey",
3108-
"model": "sentry.incident",
3109-
"nullable": false
3110-
},
3111-
"user_id": {
3112-
"kind": "HybridCloudForeignKey",
3113-
"model": "sentry.user",
3114-
"nullable": false
3115-
}
3116-
},
3117-
"model": "sentry.incidentsubscription",
3118-
"relocation_dependencies": [],
3119-
"relocation_scope": "Global",
3120-
"silos": [
3121-
"Region"
3122-
],
3123-
"table_name": "sentry_incidentsubscription",
3124-
"uniques": [
3125-
[
3126-
"incident",
3127-
"user_id"
3128-
]
3129-
]
3130-
},
31313075
"sentry.incidenttrigger": {
31323076
"dangling": false,
31333077
"foreign_keys": {
@@ -6650,4 +6594,4 @@
66506594
]
66516595
]
66526596
}
6653-
}
6597+
}

fixtures/backup/model_dependencies/flat.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,18 +424,10 @@
424424
"sentry.incident",
425425
"sentry.project"
426426
],
427-
"sentry.incidentseen": [
428-
"sentry.incident",
429-
"sentry.user"
430-
],
431427
"sentry.incidentsnapshot": [
432428
"sentry.incident",
433429
"sentry.timeseriessnapshot"
434430
],
435-
"sentry.incidentsubscription": [
436-
"sentry.incident",
437-
"sentry.user"
438-
],
439431
"sentry.incidenttrigger": [
440432
"sentry.alertruletrigger",
441433
"sentry.incident"
@@ -918,4 +910,4 @@
918910
"workflow_engine.dataconditiongroup",
919911
"workflow_engine.workflow"
920912
]
921-
}
913+
}

fixtures/backup/model_dependencies/sorted.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@
240240
"sentry.pendingincidentsnapshot",
241241
"sentry.notificationmessage",
242242
"sentry.incidenttrigger",
243-
"sentry.incidentsubscription",
244243
"sentry.incidentsnapshot",
245-
"sentry.incidentseen",
246244
"sentry.incidentproject",
247245
"sentry.incidentactivity"
248-
]
246+
]

fixtures/backup/model_dependencies/truncate.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@
240240
"sentry_pendingincidentsnapshot",
241241
"sentry_notificationmessage",
242242
"sentry_incidenttrigger",
243-
"sentry_incidentsubscription",
244243
"sentry_incidentsnapshot",
245-
"sentry_incidentseen",
246244
"sentry_incidentproject",
247245
"sentry_incidentactivity"
248-
]
246+
]

migrations_lockfile.txt

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

1616
replays: 0004_index_together
1717

18-
sentry: 0799_cron_incident_index
18+
sentry: 0800_rm_incidentseen_incidentsubscription
1919

2020
social_auth: 0002_default_auto_field
2121

src/sentry/incidents/models/incident.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
OneToOneCascadeDeletes,
2323
UUIDField,
2424
region_silo_model,
25-
sane_repr,
2625
)
2726
from sentry.db.models.fields.hybrid_cloud_foreign_key import HybridCloudForeignKey
2827
from sentry.db.models.manager.base import BaseManager
@@ -45,20 +44,6 @@ class Meta:
4544
unique_together = (("project", "incident"),)
4645

4746

48-
@region_silo_model
49-
class IncidentSeen(Model):
50-
__relocation_scope__ = RelocationScope.Excluded
51-
52-
incident = FlexibleForeignKey("sentry.Incident")
53-
user_id = HybridCloudForeignKey(settings.AUTH_USER_MODEL, on_delete="CASCADE", db_index=False)
54-
last_seen = models.DateTimeField(default=timezone.now)
55-
56-
class Meta:
57-
app_label = "sentry"
58-
db_table = "sentry_incidentseen"
59-
unique_together = (("user_id", "incident"),)
60-
61-
6247
class IncidentManager(BaseManager["Incident"]):
6348
CACHE_KEY = "incidents:active:%s:%s:%s"
6449

@@ -340,27 +325,6 @@ def normalize_before_relocation_import(
340325
return old_pk
341326

342327

343-
@region_silo_model
344-
class IncidentSubscription(Model):
345-
"""
346-
IncidentSubscription is a record of a user being subscribed to an incident.
347-
Not to be confused with a snuba QuerySubscription
348-
"""
349-
350-
__relocation_scope__ = RelocationScope.Global
351-
352-
incident = FlexibleForeignKey("sentry.Incident", db_index=False)
353-
user_id = HybridCloudForeignKey(settings.AUTH_USER_MODEL, on_delete="CASCADE")
354-
date_added = models.DateTimeField(default=timezone.now)
355-
356-
class Meta:
357-
app_label = "sentry"
358-
db_table = "sentry_incidentsubscription"
359-
unique_together = (("incident", "user_id"),)
360-
361-
__repr__ = sane_repr("incident_id", "user_id")
362-
363-
364328
class TriggerStatus(Enum):
365329
ACTIVE = 0
366330
RESOLVED = 1
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Generated by Django 5.1.1 on 2024-12-03 18:48
2+
import django
3+
from django.db import migrations
4+
5+
import sentry
6+
from sentry.new_migrations.migrations import CheckedMigration
7+
from sentry.new_migrations.monkey.models import SafeDeleteModel
8+
from sentry.new_migrations.monkey.state import DeletionAction
9+
10+
11+
class Migration(CheckedMigration):
12+
# This flag is used to mark that a migration shouldn't be automatically run in production.
13+
# This should only be used for operations where it's safe to run the migration after your
14+
# code has deployed. So this should not be used for most operations that alter the schema
15+
# of a table.
16+
# Here are some things that make sense to mark as post deployment:
17+
# - Large data migrations. Typically we want these to be run manually so that they can be
18+
# monitored and not block the deploy for a long period of time while they run.
19+
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
20+
# run this outside deployments so that we don't block them. Note that while adding an index
21+
# is a schema change, it's completely safe to run the operation after the code has deployed.
22+
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment
23+
24+
is_post_deployment = False
25+
26+
dependencies = [
27+
("sentry", "0799_cron_incident_index"),
28+
]
29+
30+
operations = [
31+
migrations.AlterField(
32+
model_name="incidentseen",
33+
name="incident",
34+
field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
35+
db_constraint=False,
36+
on_delete=django.db.models.deletion.CASCADE,
37+
to="sentry.incident",
38+
),
39+
),
40+
migrations.AlterField(
41+
model_name="incidentseen",
42+
name="user_id",
43+
field=sentry.db.models.fields.hybrid_cloud_foreign_key.HybridCloudForeignKey(
44+
"sentry.User", db_index=False, null=True, on_delete="CASCADE"
45+
),
46+
),
47+
migrations.AlterField(
48+
model_name="incidentsubscription",
49+
name="incident",
50+
field=sentry.db.models.fields.foreignkey.FlexibleForeignKey(
51+
db_constraint=False,
52+
db_index=False,
53+
on_delete=django.db.models.deletion.CASCADE,
54+
to="sentry.incident",
55+
),
56+
),
57+
migrations.AlterField(
58+
model_name="incidentsubscription",
59+
name="user_id",
60+
field=sentry.db.models.fields.hybrid_cloud_foreign_key.HybridCloudForeignKey(
61+
"sentry.User", db_index=True, null=True, on_delete="CASCADE"
62+
),
63+
),
64+
SafeDeleteModel(
65+
name="IncidentSeen",
66+
deletion_action=DeletionAction.MOVE_TO_PENDING,
67+
),
68+
SafeDeleteModel(
69+
name="IncidentSubscription",
70+
deletion_action=DeletionAction.MOVE_TO_PENDING,
71+
),
72+
]

src/sentry/testutils/helpers/backups.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
from sentry.incidents.models.incident import (
4949
IncidentActivity,
5050
IncidentSnapshot,
51-
IncidentSubscription,
5251
IncidentTrigger,
5352
PendingIncidentSnapshot,
5453
TimeSeriesSnapshot,
@@ -552,7 +551,6 @@ def create_exhaustive_organization(
552551
unique_users=1,
553552
total_events=1,
554553
)
555-
IncidentSubscription.objects.create(incident=incident, user_id=owner_id)
556554
IncidentTrigger.objects.create(
557555
incident=incident,
558556
alert_rule_trigger=trigger,

tests/sentry/backup/snapshots/SanitizationExhaustiveTests/test_clean_pks.pysnap

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
created: '2024-11-28T16:28:45.079966+00:00'
2+
created: '2024-12-03T21:15:16.898342+00:00'
33
creator: sentry
44
source: tests/sentry/backup/test_sanitize.py
55
---
@@ -868,10 +868,6 @@ source: tests/sentry/backup/test_sanitize.py
868868
sanitized_fields:
869869
- date_added
870870
- date_modified
871-
- model_name: sentry.incidentsubscription
872-
ordinal: 1
873-
sanitized_fields:
874-
- date_added
875871
- model_name: sentry.incidentsnapshot
876872
ordinal: 1
877873
sanitized_fields:

tests/sentry/backup/snapshots/test_comparators/test_default_comparators.pysnap

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
created: '2024-11-28T16:29:21.237667+00:00'
2+
created: '2024-12-03T19:31:11.333104+00:00'
33
creator: sentry
44
source: tests/sentry/backup/test_comparators.py
55
---
@@ -757,24 +757,12 @@ source: tests/sentry/backup/test_comparators.py
757757
- incident
758758
- project
759759
model_name: sentry.incidentproject
760-
- comparators:
761-
- class: ForeignKeyComparator
762-
fields:
763-
- incident
764-
- user_id
765-
model_name: sentry.incidentseen
766760
- comparators:
767761
- class: ForeignKeyComparator
768762
fields:
769763
- event_stats_snapshot
770764
- incident
771765
model_name: sentry.incidentsnapshot
772-
- comparators:
773-
- class: ForeignKeyComparator
774-
fields:
775-
- incident
776-
- user_id
777-
model_name: sentry.incidentsubscription
778766
- comparators:
779767
- class: DateUpdatedComparator
780768
fields:

0 commit comments

Comments
 (0)