:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(signals): delete retired impact measurement plans (#109535)
Mikayla Thompson97608678eff3
diff --git a/products/signals/backend/migrations/0162_delete_impact_measurement_plans.py b/products/signals/backend/migrations/0162_delete_impact_measurement_plans.pynew file mode 100644index 000000000000..6cef2b7b0dea--- /dev/null+++ b/products/signals/backend/migrations/0162_delete_impact_measurement_plans.py@@ -0,0 +1,27 @@+from django.db import migrations+from django.db.backends.base.schema import BaseDatabaseSchemaEditor+from django.db.migrations.state import StateApps++BATCH_SIZE = 500+++def delete_impact_measurement_plans(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:+ # The inbound relations to artefacts prevent a fast delete, so Django loads each doomed row before it deletes it.+ # Batches and `only("id")` keep the plan contents out of memory.+ artefact = apps.get_model("signals", "SignalReportArtefact")+ artefacts = artefact.objects.using(schema_editor.connection.alias)+ plans = artefacts.filter(type="impact_measurement_plan").order_by("id")+ cursor = None+ while True:+ page = plans.filter(id__gt=cursor) if cursor else plans+ plan_ids = list(page.values_list("id", flat=True)[:BATCH_SIZE])+ if not plan_ids:+ return+ cursor = plan_ids[-1]+ artefacts.filter(id__in=plan_ids).only("id").delete()+++class Migration(migrations.Migration):+ dependencies = [("signals", "0161_add_report_check_approval")]++ operations = [migrations.RunPython(delete_impact_measurement_plans, migrations.RunPython.noop)]diff --git a/products/signals/backend/migrations/max_migration.txt b/products/signals/backend/migrations/max_migration.txtindex 53f9952928cb..5f25594ce629 100644--- a/products/signals/backend/migrations/max_migration.txt+++ b/products/signals/backend/migrations/max_migration.txt@@ -1 +1 @@-0161_add_report_check_approval+0162_delete_impact_measurement_plans