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
This commit is contained in:
Alejandro González
2025-09-06 16:57:31 +02:00
committed by GitHub
parent 0511a14bd9
commit e2f07a7848

View File

@@ -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
"