-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Revert "Revert "feat: Add inserted_at column to events table"" (#…
…16615) Revert "Revert "feat: Add inserted_at column to events table" (#16535)" This reverts commit 59847f1.
- Loading branch information
1 parent
ff66de0
commit 53e82ed
Showing
3 changed files
with
52 additions
and
9 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
posthog/clickhouse/migrations/0047_add_insertion_timestamp_to_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,30 @@ | ||
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 | ||
|
||
ADD_COLUMNS_BASE_SQL = """ | ||
ALTER TABLE {table} | ||
ON CLUSTER '{cluster}' | ||
ADD COLUMN IF NOT EXISTS inserted_at Nullable(DateTime64(6, 'UTC')) DEFAULT NULL | ||
""" | ||
|
||
|
||
def add_columns_to_required_tables(_): | ||
sync_execute(ADD_COLUMNS_BASE_SQL.format(table="events", cluster=CLICKHOUSE_CLUSTER)) | ||
sync_execute(ADD_COLUMNS_BASE_SQL.format(table="writable_events", cluster=CLICKHOUSE_CLUSTER)) | ||
sync_execute(ADD_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(add_columns_to_required_tables), | ||
run_sql_with_exceptions(KAFKA_EVENTS_TABLE_JSON_SQL()), | ||
run_sql_with_exceptions(EVENTS_TABLE_JSON_MV_SQL()), | ||
] |
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
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