From 1bd30b3cf8e3bd6804da7ae323c73e85781aa8b4 Mon Sep 17 00:00:00 2001 From: Joey Orlando Date: Tue, 19 Nov 2024 14:23:48 -0500 Subject: [PATCH] chore: remove deprecated `AlertGroupPostMortem` model + recently refactored/deprecated slack channel related columns (#5240) # What this PR does - `AlertGroupPostMortem` has no references in the codebase.. I stumbled across it while working on https://github.com/grafana/oncall/pull/5224 and decided to just remove it - Removing old Slack channel related `VARCHAR` columns; these were refactored to foreign key references to `slack_slackchannel` table in following PRs: - https://github.com/grafana/oncall/pull/5224 - https://github.com/grafana/oncall/pull/5199 - https://github.com/grafana/oncall/pull/5191 ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] Added the relevant release notes label (see labels prefixed w/ `release:`). These labels dictate how your PR will show up in the autogenerated release notes. --- .../migrations/0001_squashed_initial.py | 2 +- ...hannelfilter__slack_channel_id_and_more.py | 26 ++++++++++ engine/apps/alerts/models/channel_filter.py | 4 -- engine/apps/alerts/models/resolution_note.py | 50 +++---------------- .../0020_remove_oncallschedule_channel.py | 19 +++++++ .../apps/schedules/models/on_call_schedule.py | 2 - ...ove_organization_general_log_channel_id.py | 19 +++++++ .../user_management/models/organization.py | 3 -- 8 files changed, 73 insertions(+), 52 deletions(-) create mode 100644 engine/apps/alerts/migrations/0066_remove_channelfilter__slack_channel_id_and_more.py create mode 100644 engine/apps/schedules/migrations/0020_remove_oncallschedule_channel.py create mode 100644 engine/apps/user_management/migrations/0028_remove_organization_general_log_channel_id.py diff --git a/engine/apps/alerts/migrations/0001_squashed_initial.py b/engine/apps/alerts/migrations/0001_squashed_initial.py index 0c96d7d4..8426d263 100644 --- a/engine/apps/alerts/migrations/0001_squashed_initial.py +++ b/engine/apps/alerts/migrations/0001_squashed_initial.py @@ -119,7 +119,7 @@ class Migration(migrations.Migration): name='AlertGroupPostmortem', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('public_primary_key', models.CharField(default=apps.alerts.models.resolution_note.generate_public_primary_key_for_alert_group_postmortem, max_length=20, unique=True, validators=[django.core.validators.MinLengthValidator(13)])), + ('public_primary_key', models.CharField(max_length=20, unique=True, validators=[django.core.validators.MinLengthValidator(13)])), ('created_at', models.DateTimeField(auto_now_add=True)), ('last_modified', models.DateTimeField(auto_now=True)), ('text', models.TextField(default=None, max_length=3000, null=True)), diff --git a/engine/apps/alerts/migrations/0066_remove_channelfilter__slack_channel_id_and_more.py b/engine/apps/alerts/migrations/0066_remove_channelfilter__slack_channel_id_and_more.py new file mode 100644 index 00000000..03c5f534 --- /dev/null +++ b/engine/apps/alerts/migrations/0066_remove_channelfilter__slack_channel_id_and_more.py @@ -0,0 +1,26 @@ +# Generated by Django 4.2.16 on 2024-11-06 21:11 + +from django.db import migrations +import django_migration_linter as linter + + +class Migration(migrations.Migration): + + dependencies = [ + ('alerts', '0065_alertreceivechannel_service_account'), + ] + + operations = [ + linter.IgnoreMigration(), + migrations.RemoveField( + model_name='channelfilter', + name='_slack_channel_id', + ), + migrations.RemoveField( + model_name='resolutionnoteslackmessage', + name='_slack_channel_id', + ), + migrations.DeleteModel( + name='AlertGroupPostmortem', + ), + ] diff --git a/engine/apps/alerts/models/channel_filter.py b/engine/apps/alerts/models/channel_filter.py index f7cb302f..3ea2ea8b 100644 --- a/engine/apps/alerts/models/channel_filter.py +++ b/engine/apps/alerts/models/channel_filter.py @@ -69,9 +69,6 @@ class ChannelFilter(OrderedModel): notify_in_slack = models.BooleanField(null=True, default=True) notify_in_telegram = models.BooleanField(null=True, default=False) - - # TODO: remove _slack_channel_id in future release - _slack_channel_id = models.CharField(max_length=100, null=True, default=None) slack_channel = models.ForeignKey( "slack.SlackChannel", null=True, @@ -79,7 +76,6 @@ class ChannelFilter(OrderedModel): on_delete=models.SET_NULL, related_name="+", ) - telegram_channel = models.ForeignKey( "telegram.TelegramToOrganizationConnector", on_delete=models.SET_NULL, diff --git a/engine/apps/alerts/models/resolution_note.py b/engine/apps/alerts/models/resolution_note.py index e2f3586a..90e65166 100644 --- a/engine/apps/alerts/models/resolution_note.py +++ b/engine/apps/alerts/models/resolution_note.py @@ -14,20 +14,7 @@ from common.utils import clean_markup if typing.TYPE_CHECKING: from apps.alerts.models import AlertGroup from apps.slack.models import SlackChannel - - -def generate_public_primary_key_for_alert_group_postmortem(): - prefix = "P" - new_public_primary_key = generate_public_primary_key(prefix) - - failure_counter = 0 - while AlertGroupPostmortem.objects.filter(public_primary_key=new_public_primary_key).exists(): - new_public_primary_key = increase_public_primary_key_length( - failure_counter=failure_counter, prefix=prefix, model_name="AlertGroupPostmortem" - ) - failure_counter += 1 - - return new_public_primary_key + from apps.user_management.models import User def generate_public_primary_key_for_resolution_note(): @@ -75,9 +62,6 @@ class ResolutionNoteSlackMessage(models.Model): related_name="added_resolution_note_slack_messages", ) text = models.TextField(max_length=3000, default=None, null=True) - - # TODO: remove _slack_channel_id in future release - _slack_channel_id = models.CharField(max_length=100, null=True, default=None) slack_channel = models.ForeignKey( "slack.SlackChannel", null=True, @@ -85,7 +69,6 @@ class ResolutionNoteSlackMessage(models.Model): on_delete=models.SET_NULL, related_name="+", ) - ts = models.CharField(max_length=100, null=True, default=None) thread_ts = models.CharField(max_length=100, null=True, default=None) permalink = models.CharField(max_length=250, null=True, default=None) @@ -130,6 +113,7 @@ class ResolutionNoteQueryset(models.QuerySet): class ResolutionNote(models.Model): alert_group: "AlertGroup" + author: typing.Optional["User"] resolution_note_slack_message: typing.Optional[ResolutionNoteSlackMessage] objects = ResolutionNoteQueryset.as_manager() @@ -213,29 +197,11 @@ class ResolutionNote(models.Model): return result - def author_verbal(self, mention): + def author_verbal(self, mention: bool) -> str: """ - Postmortems to resolution notes included migrating AlertGroupPostmortem to ResolutionNotes. - But AlertGroupPostmortem has no author field. So this method was introduces as workaround. + Postmortems to resolution notes included migrating `AlertGroupPostmortem` to `ResolutionNote`s. + But `AlertGroupPostmortem` has no author field. So this method was introduced as a workaround. + + (see git history for more details on what `AlertGroupPostmortem` was) """ - if self.author is not None: - return self.author.get_username_with_slack_verbal(mention) - else: - return "" - - -class AlertGroupPostmortem(models.Model): - public_primary_key = models.CharField( - max_length=20, - validators=[MinLengthValidator(settings.PUBLIC_PRIMARY_KEY_MIN_LENGTH + 1)], - unique=True, - default=generate_public_primary_key_for_alert_group_postmortem, - ) - alert_group = models.ForeignKey( - "alerts.AlertGroup", - on_delete=models.CASCADE, - related_name="postmortem_text", - ) - created_at = models.DateTimeField(auto_now_add=True) - last_modified = models.DateTimeField(auto_now=True) - text = models.TextField(max_length=3000, default=None, null=True) + return "" if self.author is None else self.author.get_username_with_slack_verbal(mention) diff --git a/engine/apps/schedules/migrations/0020_remove_oncallschedule_channel.py b/engine/apps/schedules/migrations/0020_remove_oncallschedule_channel.py new file mode 100644 index 00000000..e4d19138 --- /dev/null +++ b/engine/apps/schedules/migrations/0020_remove_oncallschedule_channel.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.16 on 2024-11-06 21:13 + +from django.db import migrations +import django_migration_linter as linter + + +class Migration(migrations.Migration): + + dependencies = [ + ('schedules', '0019_auto_20241021_1735'), + ] + + operations = [ + linter.IgnoreMigration(), + migrations.RemoveField( + model_name='oncallschedule', + name='channel', + ), + ] diff --git a/engine/apps/schedules/models/on_call_schedule.py b/engine/apps/schedules/models/on_call_schedule.py index 544ec847..e57cf4bc 100644 --- a/engine/apps/schedules/models/on_call_schedule.py +++ b/engine/apps/schedules/models/on_call_schedule.py @@ -209,8 +209,6 @@ class OnCallSchedule(PolymorphicModel): name = models.CharField(max_length=200) - # TODO: drop this field in a subsequent release, this has been migrated to slack_channel field - channel = models.CharField(max_length=100, null=True, default=None) slack_channel = models.ForeignKey( "slack.SlackChannel", null=True, diff --git a/engine/apps/user_management/migrations/0028_remove_organization_general_log_channel_id.py b/engine/apps/user_management/migrations/0028_remove_organization_general_log_channel_id.py new file mode 100644 index 00000000..6d415bdb --- /dev/null +++ b/engine/apps/user_management/migrations/0028_remove_organization_general_log_channel_id.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.16 on 2024-11-06 21:11 + +from django.db import migrations +import django_migration_linter as linter + + +class Migration(migrations.Migration): + + dependencies = [ + ('user_management', '0027_serviceaccount'), + ] + + operations = [ + linter.IgnoreMigration(), + migrations.RemoveField( + model_name='organization', + name='general_log_channel_id', + ), + ] diff --git a/engine/apps/user_management/models/organization.py b/engine/apps/user_management/models/organization.py index aac0aeae..2fbeefca 100644 --- a/engine/apps/user_management/models/organization.py +++ b/engine/apps/user_management/models/organization.py @@ -162,9 +162,6 @@ class Organization(MaintainableObject): slack_team_identity = models.ForeignKey( "slack.SlackTeamIdentity", on_delete=models.PROTECT, null=True, default=None, related_name="organizations" ) - - # TODO: drop this field in a subsequent release, this has been migrated to default_slack_channel field - general_log_channel_id = models.CharField(max_length=100, null=True, default=None) default_slack_channel = models.ForeignKey( "slack.SlackChannel", null=True,