posthog
posthog copied to clipboard
feat: add script to resync person on events for a team
Problem
Not fully ready yet, but wanted to make sure we agree on the approach:
- since we might need to run it more in the future - adding it as a management command to our django shell instead of a random script somewhere
- to populate the initial tables looked used select instead of what the migration did as I suspect that's a lot faster if we're talking about a single team.
Changes
👉 Stay up-to-date with PostHog coding conventions for a smoother review.
How did you test this code?
Tested locally by creating some persons and aliasing them - saw that the person_ids were updated after running the cmd
posthog.capture('test-id-2022-09-20-15-58', 'test-event-2022-09-20-15-58')
posthog.capture('test-id-2022-09-20-15-59', 'test-event-2022-09-20-15-59')
posthog.alias('test-id-2022-09-20-15-58', 'test-id-2022-09-20-15-59') # after waiting
resulted in local CH
select event, person_id from events where team_id=3
| event | person_id
|------------------------------|-----------------
│ $create_alias │ 01835b33-63fe-0000-91cc-2c4387db354b
│ test-event-2022-09-20-15-58 │ 01835b33-63fe-0000-91cc-2c4387db354b
│ test-event-2022-09-20-15-59 │ 01835b33-9b5a-0000-adc4-61a873a3c7e8
Then (also tested other steps separately)
DEBUG=1 python manage.py resync_persons_on_events --team-id 3 --live-run
resulted in local CH
select event, person_id from events where team_id=3
| event | person_id
|------------------------------|-----------------
│ $create_alias │ 01835b33-63fe-0000-91cc-2c4387db354b
│ test-event-2022-09-20-15-58 │ 01835b33-63fe-0000-91cc-2c4387db354b
│ test-event-2022-09-20-15-59 │ 01835b33-63fe-0000-91cc-2c4387db354b