diff --git a/posthog/clickhouse/migrations/0078_add_soft_delete_column_on_events.py b/posthog/clickhouse/migrations/0078_add_soft_delete_column_on_events.py index 44e7c5deee802..1450b452f9bbd 100644 --- a/posthog/clickhouse/migrations/0078_add_soft_delete_column_on_events.py +++ b/posthog/clickhouse/migrations/0078_add_soft_delete_column_on_events.py @@ -4,7 +4,7 @@ from posthog.settings import CLICKHOUSE_CLUSTER -DROP_COLUMNS_SHARDED_EVENTS = """ +DROP_COLUMNS_EVENTS = """ ALTER TABLE {table} ON CLUSTER {cluster} DROP COLUMN IF EXISTS is_deleted """ @@ -14,6 +14,11 @@ ADD COLUMN IF NOT EXISTS is_deleted DEFAULT Boolean False """ +ADD_COLUMNS_EVENTS = """ +ALTER TABLE {table} ON CLUSTER {cluster} +ADD COLUMN IF NOT EXISTS is_deleted +""" + ADD_COLUMNS_INDEX_EVENTS = """ ALTER TABLE {table} ON CLUSTER {cluster} ADD INDEX IF NOT EXISTS is_deleted_idx (is_deleted) TYPE minmax GRANULARITY 1 @@ -22,8 +27,10 @@ def add_columns_to_required_tables(_): with ch_pool.get_client() as client: - client.execute(DROP_COLUMNS_SHARDED_EVENTS.format(table="sharded_events", cluster=CLICKHOUSE_CLUSTER)) + client.execute(DROP_COLUMNS_EVENTS.format(table="sharded_events", cluster=CLICKHOUSE_CLUSTER)) + client.execute(DROP_COLUMNS_EVENTS.format(table="events", cluster=CLICKHOUSE_CLUSTER)) client.execute(ADD_COLUMNS_SHARDED_EVENTS.format(table="sharded_events", cluster=CLICKHOUSE_CLUSTER)) + client.execute(ADD_COLUMNS_EVENTS.format(table="events", cluster=CLICKHOUSE_CLUSTER)) client.execute(ADD_COLUMNS_INDEX_EVENTS.format(table="sharded_events", cluster=CLICKHOUSE_CLUSTER))