posthog/models/person_overrides/sql.py
#
from posthog.kafka_client.topics import KAFKA_PERSON_OVERRIDE
from posthog.settings.data_stores import CLICKHOUSE_CLUSTER, CLICKHOUSE_DATABASE, KAFKA_HOSTS
PERSON_OVERRIDES_CREATE_TABLE_SQL = f"""
    CREATE TABLE IF NOT EXISTS `{CLICKHOUSE_DATABASE}`.`person_overrides`
    ON CLUSTER '{CLICKHOUSE_CLUSTER}' (
        team_id INT NOT NULL,
        -- When we merge two people `old_person_id` and `override_person_id`, we
        -- want to keep track of a mapping from the `old_person_id` to the
        -- `override_person_id`. This allows us to join with the
        -- `sharded_events` table to find all events that were associated with
        -- the `old_person_id` and update them to be associated with the
        -- `override_person_id`.
        old_person_id UUID NOT NULL,
        override_person_id UUID NOT NULL,
        -- The timestamp the merge of the two people was completed.
        merged_at DateTime64(6, 'UTC') NOT NULL,
        -- The timestamp of the oldest event associated with the
        -- `old_person_id`.
        oldest_event DateTime64(6, 'UTC') NOT NULL,
        -- The timestamp rows are created. This isn't part of the JOIN process
        -- with the events table but rather a housekeeping column to allow us to
        -- see when the row was created. This shouldn't have any impact of the
        -- JOIN as it will be stored separately with the Wide ClickHouse table