From 3d448320bf11b93fcf875357ef80af7f3bc5b7b8 Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Thu, 20 Mar 2025 16:57:59 +0100 Subject: [PATCH] refactor(DB): changed DB structure for product analytics --- .../schema/db/init_dbs/clickhouse/1.23.0/1.23.0.sql | 12 ++++++++++++ .../db/init_dbs/clickhouse/create/init_schema.sql | 11 +++++++++++ .../db/rollback_dbs/clickhouse/1.23.0/1.23.0.sql | 2 ++ .../schema/db/init_dbs/clickhouse/1.23.0/1.23.0.sql | 11 +++++++++++ .../db/init_dbs/clickhouse/create/init_schema.sql | 11 +++++++++++ .../db/rollback_dbs/clickhouse/1.23.0/1.23.0.sql | 4 +++- 6 files changed, 50 insertions(+), 1 deletion(-) diff --git a/ee/scripts/schema/db/init_dbs/clickhouse/1.23.0/1.23.0.sql b/ee/scripts/schema/db/init_dbs/clickhouse/1.23.0/1.23.0.sql index 39c0822da..5d71aaad3 100644 --- a/ee/scripts/schema/db/init_dbs/clickhouse/1.23.0/1.23.0.sql +++ b/ee/scripts/schema/db/init_dbs/clickhouse/1.23.0/1.23.0.sql @@ -1 +1,13 @@ CREATE OR REPLACE FUNCTION openreplay_version AS() -> 'v1.23.0-ee'; + + +-- The full list of event-properties (used to tell which property belongs to which event) +CREATE TABLE IF NOT EXISTS product_analytics.event_properties +( + project_id UInt16, + event_name String, + property_name String, + + _timestamp DateTime DEFAULT now() +) ENGINE = ReplacingMergeTree(_timestamp) + ORDER BY (project_id, event_name, property_name); diff --git a/ee/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql b/ee/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql index 12ef017f2..7824e7cdf 100644 --- a/ee/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql +++ b/ee/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql @@ -654,6 +654,17 @@ CREATE TABLE IF NOT EXISTS product_analytics.all_events ORDER BY (project_id, event_name); +-- The full list of event-properties (used to tell which property belongs to which event) +CREATE TABLE IF NOT EXISTS product_analytics.event_properties +( + project_id UInt16, + event_name String, + property_name String, + + _timestamp DateTime DEFAULT now() +) ENGINE = ReplacingMergeTree(_timestamp) + ORDER BY (project_id, event_name, property_name); + -- The full list of properties (events and users) CREATE TABLE IF NOT EXISTS product_analytics.all_properties ( diff --git a/ee/scripts/schema/db/rollback_dbs/clickhouse/1.23.0/1.23.0.sql b/ee/scripts/schema/db/rollback_dbs/clickhouse/1.23.0/1.23.0.sql index caac93e06..bb17fac9f 100644 --- a/ee/scripts/schema/db/rollback_dbs/clickhouse/1.23.0/1.23.0.sql +++ b/ee/scripts/schema/db/rollback_dbs/clickhouse/1.23.0/1.23.0.sql @@ -1 +1,3 @@ CREATE OR REPLACE FUNCTION openreplay_version AS() -> 'v1.22.0-ee'; + +DROP TABLE IF EXISTS product_analytics.event_properties; \ No newline at end of file diff --git a/scripts/schema/db/init_dbs/clickhouse/1.23.0/1.23.0.sql b/scripts/schema/db/init_dbs/clickhouse/1.23.0/1.23.0.sql index 7b5e3ad91..ff47294b7 100644 --- a/scripts/schema/db/init_dbs/clickhouse/1.23.0/1.23.0.sql +++ b/scripts/schema/db/init_dbs/clickhouse/1.23.0/1.23.0.sql @@ -11,3 +11,14 @@ CREATE TABLE IF NOT EXISTS experimental.user_viewed_sessions PARTITION BY toYYYYMM(_timestamp) ORDER BY (project_id, user_id, session_id) TTL _timestamp + INTERVAL 3 MONTH; + +-- The full list of event-properties (used to tell which property belongs to which event) +CREATE TABLE IF NOT EXISTS product_analytics.event_properties +( + project_id UInt16, + event_name String, + property_name String, + + _timestamp DateTime DEFAULT now() +) ENGINE = ReplacingMergeTree(_timestamp) + ORDER BY (project_id, event_name, property_name); diff --git a/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql b/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql index cee2400d2..8d228868e 100644 --- a/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql +++ b/scripts/schema/db/init_dbs/clickhouse/create/init_schema.sql @@ -515,6 +515,17 @@ CREATE TABLE IF NOT EXISTS product_analytics.all_events ) ENGINE = ReplacingMergeTree(_timestamp) ORDER BY (project_id, event_name); +-- The full list of event-properties (used to tell which property belongs to which event) +CREATE TABLE IF NOT EXISTS product_analytics.event_properties +( + project_id UInt16, + event_name String, + property_name String, + + _timestamp DateTime DEFAULT now() +) ENGINE = ReplacingMergeTree(_timestamp) + ORDER BY (project_id, event_name, property_name); + -- The full list of properties (events and users) CREATE TABLE IF NOT EXISTS product_analytics.all_properties diff --git a/scripts/schema/db/rollback_dbs/clickhouse/1.23.0/1.23.0.sql b/scripts/schema/db/rollback_dbs/clickhouse/1.23.0/1.23.0.sql index dee235cd0..36def25d2 100644 --- a/scripts/schema/db/rollback_dbs/clickhouse/1.23.0/1.23.0.sql +++ b/scripts/schema/db/rollback_dbs/clickhouse/1.23.0/1.23.0.sql @@ -1,4 +1,6 @@ CREATE OR REPLACE FUNCTION openreplay_version AS() -> 'v1.22.0'; -DROP TABLE IF EXISTS experimental.user_viewed_sessions; \ No newline at end of file +DROP TABLE IF EXISTS experimental.user_viewed_sessions; + +DROP TABLE IF EXISTS product_analytics.event_properties; \ No newline at end of file