Skip to content
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
58 changes: 1 addition & 57 deletions fixtures/backup/model_dependencies/detailed.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -6650,4 +6594,4 @@
]
]
}
}
}
10 changes: 1 addition & 9 deletions fixtures/backup/model_dependencies/flat.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -918,4 +910,4 @@
"workflow_engine.dataconditiongroup",
"workflow_engine.workflow"
]
}
}
4 changes: 1 addition & 3 deletions fixtures/backup/model_dependencies/sorted.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@
"sentry.pendingincidentsnapshot",
"sentry.notificationmessage",
"sentry.incidenttrigger",
"sentry.incidentsubscription",
"sentry.incidentsnapshot",
"sentry.incidentseen",
"sentry.incidentproject",
"sentry.incidentactivity"
]
]
4 changes: 1 addition & 3 deletions fixtures/backup/model_dependencies/truncate.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,7 @@
"sentry_pendingincidentsnapshot",
"sentry_notificationmessage",
"sentry_incidenttrigger",
"sentry_incidentsubscription",
"sentry_incidentsnapshot",
"sentry_incidentseen",
"sentry_incidentproject",
"sentry_incidentactivity"
]
]
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 0 additions & 36 deletions src/sentry/incidents/models/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
),
),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I generated the 2nd part of removing the models from code it also generated this:

migrations.AlterUniqueTogether(
    name="incidentsubscription",
    unique_together=None,
),
SafeRemoveField(
    model_name="incidentsubscription",
    name="incident",
    deletion_action=DeletionAction.MOVE_TO_PENDING,
),

but it did the same in #81264 and I had removed it without issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're going to be dropping the table shortly, the AlterUniqueTogether operation isn't that important as postgres will drop the constraint when the table is dropped.

SafeDeleteModel(
name="IncidentSeen",
deletion_action=DeletionAction.MOVE_TO_PENDING,
),
SafeDeleteModel(
name="IncidentSubscription",
deletion_action=DeletionAction.MOVE_TO_PENDING,
),
]
2 changes: 0 additions & 2 deletions src/sentry/testutils/helpers/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
from sentry.incidents.models.incident import (
IncidentActivity,
IncidentSnapshot,
IncidentSubscription,
IncidentTrigger,
PendingIncidentSnapshot,
TimeSeriesSnapshot,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
---
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
---
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
---
Expand Down Expand Up @@ -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
Expand Down
Loading