From e2f07a7848e6bcc19944b2d290bb61e6443874b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Gonz=C3=A1lez?= <7822554+AlexTMjugador@users.noreply.github.com> Date: Sat, 6 Sep 2025 16:57:31 +0200 Subject: [PATCH] tweak(labrinth): create Clickhouse tables with a TTL for staging env (#4343) * tweak(labrinth): create Clickhouse tables with a TTL for staging env * chore: fix syntax error in Clickhouse DDL --- apps/labrinth/src/clickhouse/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/labrinth/src/clickhouse/mod.rs b/apps/labrinth/src/clickhouse/mod.rs index e7c2215f5..8bc009214 100644 --- a/apps/labrinth/src/clickhouse/mod.rs +++ b/apps/labrinth/src/clickhouse/mod.rs @@ -48,6 +48,13 @@ pub async fn init_client_with_database( "MergeTree()" }; + // For the Clickhouse database on the staging environment, set a TTL to avoid accumulating too much data + let ttl = if database == "staging_analytics" { + "TTL toDateTime(recorded) + INTERVAL 1 DAY" + } else { + "" + }; + client .query(&format!( " @@ -67,6 +74,7 @@ pub async fn init_client_with_database( headers Array(Tuple(String, String)) ) ENGINE = {engine} + {ttl} PRIMARY KEY (project_id, recorded, ip) SETTINGS index_granularity = 8192 " @@ -93,6 +101,7 @@ pub async fn init_client_with_database( headers Array(Tuple(String, String)) ) ENGINE = {engine} + {ttl} PRIMARY KEY (project_id, recorded, ip) SETTINGS index_granularity = 8192 " @@ -117,6 +126,7 @@ pub async fn init_client_with_database( parent UInt64 ) ENGINE = {engine} + {ttl} PRIMARY KEY (project_id, recorded, user_id) SETTINGS index_granularity = 8192 "