Fix migration for long names and do not include deleted (#2528)
This commit is contained in:
parent
0bef6efde6
commit
aef162652e
1 changed files with 4 additions and 3 deletions
|
|
@ -16,11 +16,12 @@ def convert_custom_button_to_webhook(apps, schema_editor):
|
|||
Webhooks = apps.get_model("webhooks", "Webhook")
|
||||
EscalationPolicies = apps.get_model("alerts", "EscalationPolicy")
|
||||
|
||||
for cb in CustomButton.objects.all():
|
||||
# CustomButtonManager isn't used
|
||||
for cb in CustomButton.objects.filter(deleted_at=None):
|
||||
webhook, _ = Webhooks.objects.get_or_create(
|
||||
organization=cb.organization,
|
||||
team=cb.team,
|
||||
name=cb.name + LEGACY_SUFFIX,
|
||||
name=cb.name[:100 - len(LEGACY_SUFFIX)] + LEGACY_SUFFIX,
|
||||
is_legacy=True,
|
||||
defaults=dict(
|
||||
created_at=cb.created_at,
|
||||
|
|
@ -50,7 +51,7 @@ def undo_custom_button_to_webhook(apps, schema_editor):
|
|||
|
||||
for webhook in Webhooks.objects.filter(is_legacy=True):
|
||||
try:
|
||||
cb = CustomButton.objects.get(name=webhook.name.removesuffix(LEGACY_SUFFIX), team=webhook.team, organization=webhook.organization)
|
||||
cb = CustomButton.objects.get(name__startswith=webhook.name.removesuffix(LEGACY_SUFFIX), team=webhook.team, organization=webhook.organization)
|
||||
except ObjectDoesNotExist:
|
||||
logger.warning(f"Did not find matching custom button to revert {webhook.name} {webhook.organization.stack_slug}, skipping")
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue