Skip to content

Commit

Permalink
feat: Add soft delete column to events (#24581)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuziontech authored Aug 27, 2024
1 parent b434bb8 commit 54b2bc4
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from infi.clickhouse_orm import migrations

from posthog.clickhouse.client.connection import ch_pool
from posthog.settings import CLICKHOUSE_CLUSTER


DROP_COLUMNS_EVENTS = """
ALTER TABLE {table} ON CLUSTER {cluster}
DROP COLUMN IF EXISTS is_deleted
"""

ADD_COLUMNS_EVENTS = """
ALTER TABLE {table} ON CLUSTER {cluster}
ADD COLUMN IF NOT EXISTS is_deleted Boolean
"""

ADD_COLUMNS_INDEX_EVENTS = """
ALTER TABLE {table} ON CLUSTER {cluster}
ADD INDEX IF NOT EXISTS is_deleted_idx (is_deleted) TYPE minmax GRANULARITY 1
"""


def add_columns_to_required_tables(_):
with ch_pool.get_client() as client:
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_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))


operations = [
migrations.RunPython(add_columns_to_required_tables),
]

0 comments on commit 54b2bc4

Please sign in to comment.