Skip to content

Commit

Permalink
feat(cdp): turn off all remaining legacy action webhooks (#27735)
Browse files Browse the repository at this point in the history
  • Loading branch information
meikelmosby authored Jan 22, 2025
1 parent 73ad37d commit 06eb413
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
55 changes: 55 additions & 0 deletions posthog/migrations/0552_turn_off_all_action_webhooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Generated by Django 4.2.18 on 2025-01-21 16:25

from django.db import migrations


def disable_all_action_webhooks(apps, schema_editor):
Action = apps.get_model("posthog", "Action")
Team = apps.get_model("posthog", "Team")

# Get teams that have Slack webhooks configured
teams_with_slack = (
Team.objects.exclude(slack_incoming_webhook__isnull=True)
.exclude(slack_incoming_webhook="")
.values_list("id", flat=True)
)

# Get the query without evaluating it
query = Action.objects.filter(post_to_slack=True, deleted=False, team_id__in=teams_with_slack).order_by("id")

batch_size = 100
actions_to_update = []
processed_count = 0

# Use iterator() to fetch records in batches
for action in query.iterator(chunk_size=batch_size):
action.post_to_slack = False
actions_to_update.append(action)
processed_count += 1

# Bulk update when we reach batch_size
if len(actions_to_update) >= batch_size:
Action.objects.bulk_update(actions_to_update, ["post_to_slack"])
print(f"Processed {processed_count} actions") # noqa: T201
actions_to_update = []

# Handle any remaining items
if actions_to_update:
Action.objects.bulk_update(actions_to_update, ["post_to_slack"])
print(f"Processed {processed_count} actions") # noqa: T201

print(f"Processed {processed_count} actions in total") # noqa: T201


class Migration(migrations.Migration):
dependencies = [
("posthog", "0551_batchimport"),
]

operations = [
migrations.RunPython(
disable_all_action_webhooks,
reverse_code=migrations.RunPython.noop,
elidable=True,
),
]
2 changes: 1 addition & 1 deletion posthog/migrations/max_migration.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0551_batchimport
0552_turn_off_all_action_webhooks

0 comments on commit 06eb413

Please sign in to comment.