Skip to content

Conversation

@gustavohstrassburger
Copy link
Contributor

Migration to add person_id to precalculated_person_properties table.

Context: #43816

@gustavohstrassburger gustavohstrassburger marked this pull request as ready for review December 19, 2025 21:27
@gustavohstrassburger gustavohstrassburger requested a review from a team as a code owner December 19, 2025 21:27
Copilot AI review requested due to automatic review settings December 19, 2025 21:27
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a migration to include a person_id column in the precalculated_person_properties table in ClickHouse, which is part of the work referenced in PR #43816.

Key changes:

  • Updates max_migration.txt to reference the new migration
  • Creates migration 0193 to add person_id UUID column after distinct_id in the sharded table
  • Recreates distributed tables, writable tables, Kafka tables, and materialized views to incorporate the schema change

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
posthog/clickhouse/migrations/max_migration.txt Updates migration pointer to 0193
posthog/clickhouse/migrations/0193_add_person_id_to_precalculated_person_properties.py Adds migration to alter sharded table and recreate dependent tables with person_id column

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@dustinbyrne dustinbyrne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked through this pretty extensively. It looks good. Up to you if you'd prefer someone with deeper ClickHouse knowledge take a look. 👍 👍

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="posthog/clickhouse/migrations/0193_add_person_id_to_precalculated_person_properties.py">

<violation number="1" location="posthog/clickhouse/migrations/0193_add_person_id_to_precalculated_person_properties.py:17">
P2: Missing `IF EXISTS` clause in ALTER TABLE statement. Per the migration guidelines in AGENTS.md, all ALTER TABLE statements should include `IF EXISTS` to prevent migration failures if the table doesn&#39;t exist.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="posthog/clickhouse/migrations/0193_add_person_id_to_precalculated_person_properties.py">

<violation number="1" location="posthog/clickhouse/migrations/0193_add_person_id_to_precalculated_person_properties.py:18">
P1: Missing `IF NOT EXISTS` clause. Per the ClickHouse migrations documentation, always use `IF NOT EXISTS` for `ADD COLUMN` statements to ensure migrations are idempotent and can be safely re-run.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="posthog/clickhouse/migrations/0193_add_person_id_to_precalculated_person_properties.py">

<violation number="1" location="posthog/clickhouse/migrations/0193_add_person_id_to_precalculated_person_properties.py:17">
P2: Migration removes `IF EXISTS` from `ALTER TABLE`, violating the documented convention in AGENTS.md which states: &quot;Always use `IF EXISTS` or `IF NOT EXISTS` clauses: `ALTER TABLE IF EXISTS`&quot;. This makes the migration less resilient - it will fail if the table doesn&#39;t exist instead of being a safe no-op.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

gustavohstrassburger added a commit that referenced this pull request Dec 22, 2025
@gustavohstrassburger
Copy link
Contributor Author

hey @PostHog/clickhouse, if you could please take the time to review this.

@@ -0,0 +1,48 @@
from posthog.clickhouse.client.connection import NodeRole
Copy link
Contributor

@orian orian Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while this is in general OK, I'd suggest to change the order and:

  1. drop MV

  2. drop kafka table

  3. drop writable table

  4. drop dist table

  5. modify the sharded table
    6.+ and recreate them in reverse order

ClickHouse can deal with any order, but logically this is the one following dependencies

@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Dec 22, 2025
@gustavohstrassburger gustavohstrassburger merged commit 1bc24cf into master Dec 23, 2025
155 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in Feature Flags Dec 23, 2025
@gustavohstrassburger gustavohstrassburger deleted the gusatvo/add-person-id-precalculated-person-properties branch December 23, 2025 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants