Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

explicitly set UTC timezone to the DateTime created

Blue Mouse0c07dbb9a8f8
diff --git a/migrations/clickhouse/2023_05_19.js b/migrations/clickhouse/2023_05_19.js
new file mode 100644
index 000000000..90563aa81
--- /dev/null
+++ b/migrations/clickhouse/2023_05_19.js
@@ -0,0 +1,111 @@
+const { queriesRunner, dbName } = require('./setup')
+
+const queries = [
+ // Analytics table
+ `DROP TABLE IF EXISTS ${dbName}.analytics_temp`,
+ `CREATE TABLE IF NOT EXISTS ${dbName}.analytics_temp
+ (
+ sid Nullable(String),
+ pid FixedString(12),
+ pg Nullable(String),
+ prev Nullable(String),
+ dv LowCardinality(Nullable(String)),
+ br LowCardinality(Nullable(String)),
+ os LowCardinality(Nullable(String)),
+ lc LowCardinality(Nullable(String)),
+ ref Nullable(String),
+ so Nullable(String),
+ me Nullable(String),
+ ca Nullable(String),
+ cc Nullable(FixedString(2)),
+ sdur Nullable(UInt32),
+ unique UInt8,
+ created DateTime('UTC')
+ )
+ ENGINE = MergeTree()
+ PARTITION BY toYYYYMM(created)
+ ORDER BY (pid, created);`,
+
+ `INSERT INTO ${dbName}.analytics_temp (*) SELECT * FROM ${dbName}.analytics`,
+
+ `DROP TABLE ${dbName}.analytics`,
+ `RENAME TABLE ${dbName}.analytics_temp TO ${dbName}.analytics`,
+
+ // Custom events table
+ `DROP TABLE IF EXISTS ${dbName}.customEV_temp`,
+ `CREATE TABLE IF NOT EXISTS ${dbName}.customEV
+ (
+ pid FixedString(12),
+ ev String,
+ pg Nullable(String),
+ dv LowCardinality(Nullable(String)),
+ br LowCardinality(Nullable(String)),
+ os LowCardinality(Nullable(String)),
+ lc LowCardinality(Nullable(String)),
+ ref Nullable(String),
+ so Nullable(String),
+ me Nullable(String),
+ ca Nullable(String),
+ cc Nullable(FixedString(2)),
+ created DateTime('UTC')
+ )
+ ENGINE = MergeTree()
+ PARTITION BY toYYYYMM(created)
+ ORDER BY (pid, created);`,
+
+ `INSERT INTO ${dbName}.customEV_temp (*) SELECT * FROM ${dbName}.customEV`,
+
+ `DROP TABLE ${dbName}.customEV`,
+ `RENAME TABLE ${dbName}.customEV_temp TO ${dbName}.customEV`,
+
+ // Performance table
+ `DROP TABLE IF EXISTS ${dbName}.performance_temp`,
+ `CREATE TABLE IF NOT EXISTS ${dbName}.performance
+ (
+ pid FixedString(12),
+ pg Nullable(String),
+ dv LowCardinality(Nullable(String)),
+ br LowCardinality(Nullable(String)),
+ cc Nullable(FixedString(2)),
+ dns Nullable(UInt32),
+ tls Nullable(UInt32),
+ conn Nullable(UInt32),
+ response Nullable(UInt32),
+ render Nullable(UInt32),
+ domLoad Nullable(UInt32),
+ pageLoad Nullable(UInt32),
+ ttfb Nullable(UInt32),
+ created DateTime('UTC')
+ )
+ ENGINE = MergeTree()
+ PARTITION BY toYYYYMM(created)
+ ORDER BY (pid, created);`,
+
+ `INSERT INTO ${dbName}.performance_temp (*) SELECT * FROM ${dbName}.performance`,
+
+ `DROP TABLE ${dbName}.performance`,
+ `RENAME TABLE ${dbName}.performance_temp TO ${dbName}.performance`,
+
+ // Captcha table
+ `DROP TABLE IF EXISTS ${dbName}.captcha_temp`,
+ `CREATE TABLE IF NOT EXISTS ${dbName}.captcha
+ (
+ pid FixedString(12),
+ dv LowCardinality(Nullable(String)),
+ br LowCardinality(Nullable(String)),
+ os Nullable(String),
+ cc Nullable(FixedString(2)),
+ manuallyPassed UInt8,
+ created DateTime('UTC')
+ )
+ ENGINE = MergeTree()
+ PARTITION BY toYYYYMM(created)
+ ORDER BY (pid, created);`
+
+ `INSERT INTO ${dbName}.captcha_temp (*) SELECT * FROM ${dbName}.captcha`,
+
+ `DROP TABLE ${dbName}.captcha`,
+ `RENAME TABLE ${dbName}.captcha_temp TO ${dbName}.captcha`,
+]
+
+queriesRunner(queries)
diff --git a/migrations/clickhouse/initialise_database.js b/migrations/clickhouse/initialise_database.js
index f40aa5bdc..1d529f370 100644
--- a/migrations/clickhouse/initialise_database.js
+++ b/migrations/clickhouse/initialise_database.js
@@ -24,7 +24,7 @@ const CLICKHOUSE_INIT_QUERIES = [
cc Nullable(FixedString(2)),
sdur Nullable(UInt32),
unique UInt8,
- created DateTime
+ created DateTime('UTC')
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(created)
@@ -45,7 +45,7 @@ const CLICKHOUSE_INIT_QUERIES = [
me Nullable(String),
ca Nullable(String),
cc Nullable(FixedString(2)),
- created DateTime
+ created DateTime('UTC')
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(created)
@@ -67,7 +67,7 @@ const CLICKHOUSE_INIT_QUERIES = [
domLoad Nullable(UInt32),
pageLoad Nullable(UInt32),
ttfb Nullable(UInt32),
- created DateTime
+ created DateTime('UTC')
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(created)
@@ -82,7 +82,7 @@ const CLICKHOUSE_INIT_QUERIES = [
os Nullable(String),
cc Nullable(FixedString(2)),
manuallyPassed UInt8,
- created DateTime
+ created DateTime('UTC')
)
ENGINE = MergeTree()
PARTITION BY toYYYYMM(created)