-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add soft delete column to events (#24581)
- Loading branch information
1 parent
b434bb8
commit 54b2bc4
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
posthog/clickhouse/migrations/0078_add_soft_delete_column_on_events.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
] |