Skip to content

: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.

fix(replay-vision): drop orphaned vision action tables (#97901)

Eli Reismane1e9716ea3d1
diff --git a/products/replay_vision/backend/migrations/0093_drop_visionaction_tables.py b/products/replay_vision/backend/migrations/0093_drop_visionaction_tables.py
new file mode 100644
index 000000000000..83636f25d838
--- /dev/null
+++ b/products/replay_vision/backend/migrations/0093_drop_visionaction_tables.py
@@ -0,0 +1,40 @@
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+ """Drop the orphaned replay_vision_visionaction and replay_vision_visionactionrun tables.
+
+ Migration 0086 removed VisionAction and VisionActionRun from Django's model state with
+ SeparateDatabaseAndState and left both physical tables in place. It passed no
+ database_operations, so the tables kept every foreign key they had, including
+ visionaction.team_id and visionactionrun.team_id which both reference posthog_team.
+
+ Django no longer knows the two tables exist, so a cascade delete never removes their rows.
+ Every FK on them is DEFERRABLE INITIALLY DEFERRED, so a Team delete runs its whole cascade
+ and then fails at COMMIT with a ForeignKeyViolation. That makes team and organization
+ deletion impossible, and the failing transaction holds SELECT FOR UPDATE on posthog_team
+ while it runs, which blocks any concurrent insert that needs FOR KEY SHARE on the same team
+ row.
+
+ This is the second phase from safe-django-migrations.md "Dropping Tables". Dropping each
+ table also drops its foreign keys, which is what unblocks the cascade.
+
+ visionactionrun is dropped first because it references visionaction.
+
+ Irreversible: the row data is gone. The reverse is a no-op rather than a bogus CREATE TABLE,
+ so unapplying this leaves both tables absent, which no code reads or writes.
+ """
+
+ dependencies = [
+ ("replay_vision", "0092_replayobservationview"),
+ ]
+
+ operations = [
+ migrations.RunSQL(
+ sql="""
+ DROP TABLE IF EXISTS "replay_vision_visionactionrun";
+ DROP TABLE IF EXISTS "replay_vision_visionaction";
+ """,
+ reverse_sql=migrations.RunSQL.noop,
+ ),
+ ]
diff --git a/products/replay_vision/backend/migrations/max_migration.txt b/products/replay_vision/backend/migrations/max_migration.txt
index 7bc465991128..c60035d4be91 100644
--- a/products/replay_vision/backend/migrations/max_migration.txt
+++ b/products/replay_vision/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0092_replayobservationview
+0093_drop_visionaction_tables