From 27c5529a7e4d6b8378a334344b04eb3fe7243dbd Mon Sep 17 00:00:00 2001 From: Colleen O'Rourke Date: Tue, 3 Dec 2024 11:00:06 -0800 Subject: [PATCH 1/5] chore(alerts): Remove incidentseen and incidentsubscription models --- migrations_lockfile.txt | 2 +- src/sentry/incidents/models/incident.py | 36 ---------- ...00_rm_incidentseen_incidentsubscription.py | 72 +++++++++++++++++++ src/sentry/testutils/helpers/backups.py | 2 - 4 files changed, 73 insertions(+), 39 deletions(-) create mode 100644 src/sentry/migrations/0800_rm_incidentseen_incidentsubscription.py diff --git a/migrations_lockfile.txt b/migrations_lockfile.txt index 12164df5ebdb2b..4929547058d7ae 100644 --- a/migrations_lockfile.txt +++ b/migrations_lockfile.txt @@ -15,7 +15,7 @@ remote_subscriptions: 0003_drop_remote_subscription replays: 0004_index_together -sentry: 0799_cron_incident_index +sentry: 0800_rm_incidentseen_incidentsubscription social_auth: 0002_default_auto_field diff --git a/src/sentry/incidents/models/incident.py b/src/sentry/incidents/models/incident.py index 392ad8111950d3..1d64379b142813 100644 --- a/src/sentry/incidents/models/incident.py +++ b/src/sentry/incidents/models/incident.py @@ -22,7 +22,6 @@ OneToOneCascadeDeletes, UUIDField, region_silo_model, - sane_repr, ) from sentry.db.models.fields.hybrid_cloud_foreign_key import HybridCloudForeignKey from sentry.db.models.manager.base import BaseManager @@ -45,20 +44,6 @@ class Meta: unique_together = (("project", "incident"),) -@region_silo_model -class IncidentSeen(Model): - __relocation_scope__ = RelocationScope.Excluded - - incident = FlexibleForeignKey("sentry.Incident") - user_id = HybridCloudForeignKey(settings.AUTH_USER_MODEL, on_delete="CASCADE", db_index=False) - last_seen = models.DateTimeField(default=timezone.now) - - class Meta: - app_label = "sentry" - db_table = "sentry_incidentseen" - unique_together = (("user_id", "incident"),) - - class IncidentManager(BaseManager["Incident"]): CACHE_KEY = "incidents:active:%s:%s:%s" @@ -340,27 +325,6 @@ def normalize_before_relocation_import( return old_pk -@region_silo_model -class IncidentSubscription(Model): - """ - IncidentSubscription is a record of a user being subscribed to an incident. - Not to be confused with a snuba QuerySubscription - """ - - __relocation_scope__ = RelocationScope.Global - - incident = FlexibleForeignKey("sentry.Incident", db_index=False) - user_id = HybridCloudForeignKey(settings.AUTH_USER_MODEL, on_delete="CASCADE") - date_added = models.DateTimeField(default=timezone.now) - - class Meta: - app_label = "sentry" - db_table = "sentry_incidentsubscription" - unique_together = (("incident", "user_id"),) - - __repr__ = sane_repr("incident_id", "user_id") - - class TriggerStatus(Enum): ACTIVE = 0 RESOLVED = 1 diff --git a/src/sentry/migrations/0800_rm_incidentseen_incidentsubscription.py b/src/sentry/migrations/0800_rm_incidentseen_incidentsubscription.py new file mode 100644 index 00000000000000..5a77729743455f --- /dev/null +++ b/src/sentry/migrations/0800_rm_incidentseen_incidentsubscription.py @@ -0,0 +1,72 @@ +# Generated by Django 5.1.1 on 2024-12-03 18:48 +import django +from django.db import migrations + +import sentry +from sentry.new_migrations.migrations import CheckedMigration +from sentry.new_migrations.monkey.models import SafeDeleteModel +from sentry.new_migrations.monkey.state import DeletionAction + + +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", "0799_cron_incident_index"), + ] + + operations = [ + migrations.AlterField( + model_name="incidentseen", + name="incident", + field=sentry.db.models.fields.foreignkey.FlexibleForeignKey( + db_constraint=False, + on_delete=django.db.models.deletion.CASCADE, + to="sentry.incident", + ), + ), + migrations.AlterField( + model_name="incidentseen", + name="user_id", + field=sentry.db.models.fields.hybrid_cloud_foreign_key.HybridCloudForeignKey( + "sentry.User", db_index=False, null=True, on_delete="CASCADE" + ), + ), + migrations.AlterField( + model_name="incidentsubscription", + name="incident", + field=sentry.db.models.fields.foreignkey.FlexibleForeignKey( + db_constraint=False, + db_index=False, + on_delete=django.db.models.deletion.CASCADE, + to="sentry.incident", + ), + ), + migrations.AlterField( + model_name="incidentsubscription", + name="user_id", + field=sentry.db.models.fields.hybrid_cloud_foreign_key.HybridCloudForeignKey( + "sentry.User", db_index=True, null=True, on_delete="CASCADE" + ), + ), + SafeDeleteModel( + name="IncidentSeen", + deletion_action=DeletionAction.MOVE_TO_PENDING, + ), + SafeDeleteModel( + name="IncidentSubscription", + deletion_action=DeletionAction.MOVE_TO_PENDING, + ), + ] diff --git a/src/sentry/testutils/helpers/backups.py b/src/sentry/testutils/helpers/backups.py index 2af45398ed20ce..6e4348f39e7a40 100644 --- a/src/sentry/testutils/helpers/backups.py +++ b/src/sentry/testutils/helpers/backups.py @@ -48,7 +48,6 @@ from sentry.incidents.models.incident import ( IncidentActivity, IncidentSnapshot, - IncidentSubscription, IncidentTrigger, PendingIncidentSnapshot, TimeSeriesSnapshot, @@ -552,7 +551,6 @@ def create_exhaustive_organization( unique_users=1, total_events=1, ) - IncidentSubscription.objects.create(incident=incident, user_id=owner_id) IncidentTrigger.objects.create( incident=incident, alert_rule_trigger=trigger, From acb40a5d85cd1537fecdd2cbc57a10db7a613084 Mon Sep 17 00:00:00 2001 From: Colleen O'Rourke Date: Tue, 3 Dec 2024 11:31:18 -0800 Subject: [PATCH 2/5] update snapshots --- .../test_default_comparators.pysnap | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/tests/sentry/backup/snapshots/test_comparators/test_default_comparators.pysnap b/tests/sentry/backup/snapshots/test_comparators/test_default_comparators.pysnap index 7df63bc2475851..579421b19e7a02 100644 --- a/tests/sentry/backup/snapshots/test_comparators/test_default_comparators.pysnap +++ b/tests/sentry/backup/snapshots/test_comparators/test_default_comparators.pysnap @@ -1,5 +1,5 @@ --- -created: '2024-11-28T16:29:21.237667+00:00' +created: '2024-12-03T19:31:11.333104+00:00' creator: sentry source: tests/sentry/backup/test_comparators.py --- @@ -757,24 +757,12 @@ source: tests/sentry/backup/test_comparators.py - incident - project model_name: sentry.incidentproject -- comparators: - - class: ForeignKeyComparator - fields: - - incident - - user_id - model_name: sentry.incidentseen - comparators: - class: ForeignKeyComparator fields: - event_stats_snapshot - incident model_name: sentry.incidentsnapshot -- comparators: - - class: ForeignKeyComparator - fields: - - incident - - user_id - model_name: sentry.incidentsubscription - comparators: - class: DateUpdatedComparator fields: From 5ff80ca47e84beadb5a580085a2b1551fb3a14c2 Mon Sep 17 00:00:00 2001 From: Colleen O'Rourke Date: Tue, 3 Dec 2024 12:13:50 -0800 Subject: [PATCH 3/5] update fixtures --- .../backup/model_dependencies/detailed.json | 58 +------------------ fixtures/backup/model_dependencies/flat.json | 10 +--- .../backup/model_dependencies/sorted.json | 4 +- .../backup/model_dependencies/truncate.json | 4 +- 4 files changed, 4 insertions(+), 72 deletions(-) diff --git a/fixtures/backup/model_dependencies/detailed.json b/fixtures/backup/model_dependencies/detailed.json index b1724a1f54dede..7cd2989f951e07 100644 --- a/fixtures/backup/model_dependencies/detailed.json +++ b/fixtures/backup/model_dependencies/detailed.json @@ -3045,34 +3045,6 @@ ] ] }, - "sentry.incidentseen": { - "dangling": false, - "foreign_keys": { - "incident": { - "kind": "FlexibleForeignKey", - "model": "sentry.incident", - "nullable": false - }, - "user_id": { - "kind": "HybridCloudForeignKey", - "model": "sentry.user", - "nullable": false - } - }, - "model": "sentry.incidentseen", - "relocation_dependencies": [], - "relocation_scope": "Excluded", - "silos": [ - "Region" - ], - "table_name": "sentry_incidentseen", - "uniques": [ - [ - "incident", - "user_id" - ] - ] - }, "sentry.incidentsnapshot": { "dangling": false, "foreign_keys": { @@ -3100,34 +3072,6 @@ ] ] }, - "sentry.incidentsubscription": { - "dangling": false, - "foreign_keys": { - "incident": { - "kind": "FlexibleForeignKey", - "model": "sentry.incident", - "nullable": false - }, - "user_id": { - "kind": "HybridCloudForeignKey", - "model": "sentry.user", - "nullable": false - } - }, - "model": "sentry.incidentsubscription", - "relocation_dependencies": [], - "relocation_scope": "Global", - "silos": [ - "Region" - ], - "table_name": "sentry_incidentsubscription", - "uniques": [ - [ - "incident", - "user_id" - ] - ] - }, "sentry.incidenttrigger": { "dangling": false, "foreign_keys": { @@ -6650,4 +6594,4 @@ ] ] } -} +} \ No newline at end of file diff --git a/fixtures/backup/model_dependencies/flat.json b/fixtures/backup/model_dependencies/flat.json index 524f68815f982b..c8a043ef9367c2 100644 --- a/fixtures/backup/model_dependencies/flat.json +++ b/fixtures/backup/model_dependencies/flat.json @@ -424,18 +424,10 @@ "sentry.incident", "sentry.project" ], - "sentry.incidentseen": [ - "sentry.incident", - "sentry.user" - ], "sentry.incidentsnapshot": [ "sentry.incident", "sentry.timeseriessnapshot" ], - "sentry.incidentsubscription": [ - "sentry.incident", - "sentry.user" - ], "sentry.incidenttrigger": [ "sentry.alertruletrigger", "sentry.incident" @@ -918,4 +910,4 @@ "workflow_engine.dataconditiongroup", "workflow_engine.workflow" ] -} +} \ No newline at end of file diff --git a/fixtures/backup/model_dependencies/sorted.json b/fixtures/backup/model_dependencies/sorted.json index bbb00e24e88d2a..0d3184b41b5679 100644 --- a/fixtures/backup/model_dependencies/sorted.json +++ b/fixtures/backup/model_dependencies/sorted.json @@ -240,9 +240,7 @@ "sentry.pendingincidentsnapshot", "sentry.notificationmessage", "sentry.incidenttrigger", - "sentry.incidentsubscription", "sentry.incidentsnapshot", - "sentry.incidentseen", "sentry.incidentproject", "sentry.incidentactivity" -] +] \ No newline at end of file diff --git a/fixtures/backup/model_dependencies/truncate.json b/fixtures/backup/model_dependencies/truncate.json index 3326320eac2492..5dd22a1e6a9e44 100644 --- a/fixtures/backup/model_dependencies/truncate.json +++ b/fixtures/backup/model_dependencies/truncate.json @@ -240,9 +240,7 @@ "sentry_pendingincidentsnapshot", "sentry_notificationmessage", "sentry_incidenttrigger", - "sentry_incidentsubscription", "sentry_incidentsnapshot", - "sentry_incidentseen", "sentry_incidentproject", "sentry_incidentactivity" -] +] \ No newline at end of file From 827b2afd86cc004af43f701f8b6fe9d08992b96d Mon Sep 17 00:00:00 2001 From: Colleen O'Rourke Date: Tue, 3 Dec 2024 12:17:14 -0800 Subject: [PATCH 4/5] update another snapshot --- .../snapshots/PreprocessingTransferTest/test_success.pysnap | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/sentry/tasks/snapshots/PreprocessingTransferTest/test_success.pysnap b/tests/sentry/tasks/snapshots/PreprocessingTransferTest/test_success.pysnap index 2692db78df58c1..1fe65ca894a88d 100644 --- a/tests/sentry/tasks/snapshots/PreprocessingTransferTest/test_success.pysnap +++ b/tests/sentry/tasks/snapshots/PreprocessingTransferTest/test_success.pysnap @@ -1,5 +1,5 @@ --- -created: '2024-11-27T19:39:08.913265+00:00' +created: '2024-12-03T20:16:20.099220+00:00' creator: sentry source: tests/sentry/tasks/test_relocation.py --- @@ -96,7 +96,7 @@ steps: - -U - postgres - -c - - TRUNCATE sentry_controloption,sentry_integration,sentry_option,sentry_organization,sentry_organizationintegration,sentry_organizationoptions,sentry_projecttemplate,sentry_projecttemplateoption,sentry_relay,sentry_relayusage,sentry_repository,sentry_team,auth_user,sentry_userip,sentry_userpermission,sentry_userrole,sentry_userrole_users,workflow_engine_dataconditiongroup,workflow_engine_datasource,workflow_engine_datacondition,sentry_savedsearch,sentry_recentsearch,sentry_project,sentry_orgauthtoken,sentry_organizationmember,sentry_organizationaccessrequest,sentry_monitor,sentry_groupsearchview,sentry_environment,sentry_email,sentry_datasecrecywaiver,sentry_dashboardtombstone,sentry_dashboard,sentry_customdynamicsamplingrule,sentry_projectcounter,sentry_authprovider,sentry_authidentity,auth_authenticator,sentry_apikey,sentry_apiapplication,workflow_engine_workflow,workflow_engine_detector,workflow_engine_datasourcedetector,sentry_useroption,sentry_useremail,sentry_snubaquery,sentry_sentryapp,sentry_rule,sentry_querysubscription,sentry_projectteam,sentry_projectredirect,sentry_projectownership,sentry_projectoptions,sentry_projectkey,sentry_projectintegration,sentry_projectbookmark,sentry_organizationmember_teams,sentry_notificationaction,sentry_neglectedrule,sentry_environmentproject,sentry_dashboardwidget,sentry_dashboardpermissions,sentry_dashboardfavoriteuser,sentry_customdynamicsamplingruleproject,sentry_apitoken,sentry_apigrant,sentry_apiauthorization,sentry_alertrule,workflow_engine_workflowdataconditiongroup,workflow_engine_detectorworkflow,sentry_snubaqueryeventtype,sentry_sentryappinstallation,sentry_sentryappcomponent,sentry_rulesnooze,sentry_ruleactivity,sentry_notificationactionproject,sentry_dashboardwidgetquery,sentry_dashboardpermissionsteam,sentry_alertruletrigger,sentry_alertruleprojects,sentry_alertruleactivity,sentry_alertruleactivationcondition,sentry_servicehook,sentry_incident,sentry_dashboardwidgetqueryondemand,sentry_alertruletriggeraction,sentry_timeseriessnapshot,sentry_pendingincidentsnapshot,sentry_incidenttrigger,sentry_incidentsubscription,sentry_incidentsnapshot,sentry_incidentactivity + - TRUNCATE sentry_controloption,sentry_integration,sentry_option,sentry_organization,sentry_organizationintegration,sentry_organizationoptions,sentry_projecttemplate,sentry_projecttemplateoption,sentry_relay,sentry_relayusage,sentry_repository,sentry_team,auth_user,sentry_userip,sentry_userpermission,sentry_userrole,sentry_userrole_users,workflow_engine_dataconditiongroup,workflow_engine_datasource,workflow_engine_datacondition,sentry_savedsearch,sentry_recentsearch,sentry_project,sentry_orgauthtoken,sentry_organizationmember,sentry_organizationaccessrequest,sentry_monitor,sentry_groupsearchview,sentry_environment,sentry_email,sentry_datasecrecywaiver,sentry_dashboardtombstone,sentry_dashboard,sentry_customdynamicsamplingrule,sentry_projectcounter,sentry_authprovider,sentry_authidentity,auth_authenticator,sentry_apikey,sentry_apiapplication,workflow_engine_workflow,workflow_engine_detector,workflow_engine_datasourcedetector,sentry_useroption,sentry_useremail,sentry_snubaquery,sentry_sentryapp,sentry_rule,sentry_querysubscription,sentry_projectteam,sentry_projectredirect,sentry_projectownership,sentry_projectoptions,sentry_projectkey,sentry_projectintegration,sentry_projectbookmark,sentry_organizationmember_teams,sentry_notificationaction,sentry_neglectedrule,sentry_environmentproject,sentry_dashboardwidget,sentry_dashboardpermissions,sentry_dashboardfavoriteuser,sentry_customdynamicsamplingruleproject,sentry_apitoken,sentry_apigrant,sentry_apiauthorization,sentry_alertrule,workflow_engine_workflowdataconditiongroup,workflow_engine_detectorworkflow,sentry_snubaqueryeventtype,sentry_sentryappinstallation,sentry_sentryappcomponent,sentry_rulesnooze,sentry_ruleactivity,sentry_notificationactionproject,sentry_dashboardwidgetquery,sentry_dashboardpermissionsteam,sentry_alertruletrigger,sentry_alertruleprojects,sentry_alertruleactivity,sentry_alertruleactivationcondition,sentry_servicehook,sentry_incident,sentry_dashboardwidgetqueryondemand,sentry_alertruletriggeraction,sentry_timeseriessnapshot,sentry_pendingincidentsnapshot,sentry_incidenttrigger,sentry_incidentsnapshot,sentry_incidentactivity RESTART IDENTITY CASCADE; id: clear-database name: gcr.io/cloud-builders/docker From 87a812d32e851fe940063150c496e442c1b7ff21 Mon Sep 17 00:00:00 2001 From: Colleen O'Rourke Date: Tue, 3 Dec 2024 13:16:07 -0800 Subject: [PATCH 5/5] update another snapshot --- .../SanitizationExhaustiveTests/test_clean_pks.pysnap | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/sentry/backup/snapshots/SanitizationExhaustiveTests/test_clean_pks.pysnap b/tests/sentry/backup/snapshots/SanitizationExhaustiveTests/test_clean_pks.pysnap index ba1c806870e4c5..a31e4219cfddae 100644 --- a/tests/sentry/backup/snapshots/SanitizationExhaustiveTests/test_clean_pks.pysnap +++ b/tests/sentry/backup/snapshots/SanitizationExhaustiveTests/test_clean_pks.pysnap @@ -1,5 +1,5 @@ --- -created: '2024-11-28T16:28:45.079966+00:00' +created: '2024-12-03T21:15:16.898342+00:00' creator: sentry source: tests/sentry/backup/test_sanitize.py --- @@ -868,10 +868,6 @@ source: tests/sentry/backup/test_sanitize.py sanitized_fields: - date_added - date_modified -- model_name: sentry.incidentsubscription - ordinal: 1 - sanitized_fields: - - date_added - model_name: sentry.incidentsnapshot ordinal: 1 sanitized_fields: