Skip to content

Commit e2f07a7

Browse files
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
1 parent 0511a14 commit e2f07a7

File tree

1 file changed

+10
-0
lines changed
  • apps/labrinth/src/clickhouse

1 file changed

+10
-0
lines changed

apps/labrinth/src/clickhouse/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ pub async fn init_client_with_database(
4848
"MergeTree()"
4949
};
5050

51+
// For the Clickhouse database on the staging environment, set a TTL to avoid accumulating too much data
52+
let ttl = if database == "staging_analytics" {
53+
"TTL toDateTime(recorded) + INTERVAL 1 DAY"
54+
} else {
55+
""
56+
};
57+
5158
client
5259
.query(&format!(
5360
"
@@ -67,6 +74,7 @@ pub async fn init_client_with_database(
6774
headers Array(Tuple(String, String))
6875
)
6976
ENGINE = {engine}
77+
{ttl}
7078
PRIMARY KEY (project_id, recorded, ip)
7179
SETTINGS index_granularity = 8192
7280
"
@@ -93,6 +101,7 @@ pub async fn init_client_with_database(
93101
headers Array(Tuple(String, String))
94102
)
95103
ENGINE = {engine}
104+
{ttl}
96105
PRIMARY KEY (project_id, recorded, ip)
97106
SETTINGS index_granularity = 8192
98107
"
@@ -117,6 +126,7 @@ pub async fn init_client_with_database(
117126
parent UInt64
118127
)
119128
ENGINE = {engine}
129+
{ttl}
120130
PRIMARY KEY (project_id, recorded, user_id)
121131
SETTINGS index_granularity = 8192
122132
"

0 commit comments

Comments
 (0)