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.
This commit is contained in:
Joey Orlando 2024-11-19 14:23:48 -05:00 committed by GitHub
parent 2bcbac8454
commit 1bd30b3cf8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 73 additions and 52 deletions

View file

@ -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)),

View file

@ -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',
),
]

View file

@ -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,

View file

@ -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)

View file

@ -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',
),
]

View file

@ -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,

View file

@ -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',
),
]

View file

@ -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,