From 3034ef2edd55f6544cdbbc4c1aec4e6a0cb70287 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Tue, 8 Mar 2022 18:54:10 +0100 Subject: [PATCH] fix(TTL): tables now have a default TTL for data of 1 MONTH --- ts/smartclickhouse.classes.timedatatable.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ts/smartclickhouse.classes.timedatatable.ts b/ts/smartclickhouse.classes.timedatatable.ts index efd4be3..196efa3 100644 --- a/ts/smartclickhouse.classes.timedatatable.ts +++ b/ts/smartclickhouse.classes.timedatatable.ts @@ -32,10 +32,18 @@ export class TimeDataTable { // create table in clickhouse await smartClickHouseDbRefArg.clickhouseClient - .queryPromise(`CREATE TABLE IF NOT EXISTS ${newTable.tableName} ( - timestamp DateTime64(3, 'Europe/Berlin'), - message String - ) ENGINE=MergeTree() ORDER BY timestamp`); + .queryPromise(` + CREATE TABLE IF NOT EXISTS ${newTable.tableName} ( + timestamp DateTime64(3, 'Europe/Berlin'), + message String + ) ENGINE=MergeTree() ORDER BY timestamp + `); + + // lets adjust the TTL + await smartClickHouseDbRefArg.clickhouseClient + .queryPromise(` + ALTER TABLE ${newTable.tableName} MODIFY TTL toDateTime(timestamp) + INTERVAL 1 MONTH; + `); await newTable.updateColumns(); console.log(`=======================`)