Skip to content

Commit

Permalink
fix: Delete cohort people query (#27224)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Jan 2, 2025
1 parent f85c053 commit cf723e2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions posthog/management/commands/delete_persons.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def run(options):
WHERE team_id = %(team_id)s AND (old_person_id IN (SELECT id FROM to_delete) OR override_person_id IN (SELECT id FROM to_delete));
"""

delete_query_cohort_people = f"""
WITH to_delete AS ({select_query})
DELETE FROM posthog_cohortpeople
WHERE team_id = %(team_id)s AND person_id IN (SELECT id FROM to_delete);
"""

delete_query_person = f"""
WITH to_delete AS ({select_query})
DELETE FROM posthog_person
Expand All @@ -77,13 +83,17 @@ def run(options):
prepared_person_override_query = cursor.mogrify(
delete_query_person_override, {"team_id": team_id, "limit": batch_size, "person_ids": person_ids}
)
prepared_cohort_people_query = cursor.mogrify(
delete_query_cohort_people, {"team_id": team_id, "limit": batch_size, "person_ids": person_ids}
)
prepared_person_query = cursor.mogrify(
delete_query_person, {"team_id": team_id, "limit": batch_size, "person_ids": person_ids}
)

logger.info(f"Delete query to run:")
logger.info(prepared_person_distinct_ids_query)
logger.info(prepared_person_override_query)
logger.info(prepared_cohort_people_query)
logger.info(prepared_person_query)

if not live_run:
Expand All @@ -109,6 +119,12 @@ def run(options):
delete_query_person_override, {"team_id": team_id, "limit": batch_size, "person_ids": person_ids}
)
logger.info(f"Deleted {cursor.rowcount} person overrides")

cursor.execute(
delete_query_cohort_people, {"team_id": team_id, "limit": batch_size, "person_ids": person_ids}
)
logger.info(f"Deleted {cursor.rowcount} cohort people")

cursor.execute(delete_query_person, {"team_id": team_id, "limit": batch_size, "person_ids": person_ids})
logger.info(f"Deleted {cursor.rowcount} persons")

Expand Down

0 comments on commit cf723e2

Please sign in to comment.