posthog/models/person_overrides/sql.py
-- `old_person_id` in multiple partitions during the merge process.
    PARTITION BY toYYYYMM(oldest_event)
    -- We want to collapse down on the `old_person_id` such that we end up with
    -- the newest known mapping for it in the table. Query side we will need to
    -- ensure that we are always querying the latest version of the mapping.
    ORDER BY (team_id, old_person_id)
"""
KAFKA_PERSON_OVERRIDES_TABLE_SQL = f"""
    CREATE TABLE IF NOT EXISTS `{CLICKHOUSE_DATABASE}`.`kafka_person_overrides`
    ON CLUSTER '{CLICKHOUSE_CLUSTER}'
    ENGINE = Kafka(
        '{KAFKA_HOSTS}', -- Kafka hosts
        '{KAFKA_PERSON_OVERRIDE}', -- Kafka topic
        'clickhouse-person-overrides', -- Kafka consumer group id
        'JSONEachRow' -- Specify that we should pass Kafka messages as JSON
    )
    -- Take the types from the `person_overrides` table, except for the
    -- `created_at`, which we want to use the DEFAULT now() from the
    -- `person_overrides` definition. See
    -- https://github.com/ClickHouse/ClickHouse/pull/38272 for details of `EMPTY
    -- AS SELECT`
    EMPTY AS SELECT
        team_id,
        old_person_id,
        override_person_id,
        merged_at,
        oldest_event,
        -- We don't want to insert this column via Kafka, as it's
        -- set as a default value in the `person_overrides` table.
        -- created_at,