Skip to content

Commit

Permalink
chore: add CH migration to add new person_mode option
Browse files Browse the repository at this point in the history
  • Loading branch information
bretthoerner committed Apr 24, 2024
1 parent a851ace commit d965575
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions posthog/clickhouse/migrations/0060_person_mode_force_upgrade.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from infi.clickhouse_orm import migrations

from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
from posthog.client import sync_execute
from posthog.models.event.sql import (
EVENTS_TABLE_JSON_MV_SQL,
KAFKA_EVENTS_TABLE_JSON_SQL,
)
from posthog.settings import CLICKHOUSE_CLUSTER


# Column was added in 0057_events_person_mode
ALTER_COLUMNS_BASE_SQL = """
ALTER TABLE {table}
ON CLUSTER {cluster}
MODIFY COLUMN person_mode Enum8('full' = 0, 'propertyless' = 1, 'force_upgrade' = 2)
"""


def alter_columns_in_required_tables(_):
sync_execute(ALTER_COLUMNS_BASE_SQL.format(table="events", cluster=CLICKHOUSE_CLUSTER))
sync_execute(ALTER_COLUMNS_BASE_SQL.format(table="writable_events", cluster=CLICKHOUSE_CLUSTER))
sync_execute(ALTER_COLUMNS_BASE_SQL.format(table="sharded_events", cluster=CLICKHOUSE_CLUSTER))


operations = [
run_sql_with_exceptions(f"DROP TABLE IF EXISTS events_json_mv ON CLUSTER '{CLICKHOUSE_CLUSTER}'"),
run_sql_with_exceptions(f"DROP TABLE IF EXISTS kafka_events_json ON CLUSTER '{CLICKHOUSE_CLUSTER}'"),
migrations.RunPython(alter_columns_in_required_tables),
run_sql_with_exceptions(KAFKA_EVENTS_TABLE_JSON_SQL()),
run_sql_with_exceptions(EVENTS_TABLE_JSON_MV_SQL()),
]

0 comments on commit d965575

Please sign in to comment.