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!

added migration to use LowCardinality superstructure for improved performance

Blue Mouse054df5af6ef8
diff --git a/migrations/clickhouse/2023_04_25.js b/migrations/clickhouse/2023_04_25.js
new file mode 100644
index 000000000..711cf19b2
--- /dev/null
+++ b/migrations/clickhouse/2023_04_25.js
@@ -0,0 +1,63 @@
+const { queriesRunner, dbName } = require('./setup')
+
+const queries = [
+ // Analytics -> LowCardinality
+ `DROP TABLE IF EXISTS ${dbName}.analytics_temp`,
+ `CREATE TABLE IF NOT EXISTS ${dbName}.analytics_temp
+ (
+ sid Nullable(String),
+ pid FixedString(12),
+ 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 LowCardinality(Nullable(FixedString(2))),
+ sdur Nullable(UInt32),
+ unique UInt8,
+ created DateTime
+ )
+ ENGINE = MergeTree()
+ PARTITION BY toYYYYMM(created)
+ ORDER BY (pid, created);`,
+
+ `INSERT INTO ${dbName}.analytics_temp (sid, pid, pg, dv, br, os, lc, ref, so, me, ca, cc, sdur, unique, created)
+ SELECT sid, pid, pg, dv, br, os, lc, ref, so, me, ca, cc, sdur, unique, created FROM ${dbName}.analytics`,
+
+ `DROP TABLE ${dbName}.analytics`,
+ `RENAME TABLE ${dbName}.analytics_temp TO ${dbName}.analytics`,
+
+ // Custom events -> LowCardinality
+ `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 LowCardinality(Nullable(FixedString(2))),
+ created DateTime
+ )
+ ENGINE = MergeTree()
+ PARTITION BY toYYYYMM(created)
+ ORDER BY (pid, created);`,
+
+ `INSERT INTO ${dbName}.customEV (pid, ev, pg, dv, br, os, lc, ref, so, me, ca, cc, created)
+ SELECT pid, ev, pg, dv, br, os, lc, ref, so, me, ca, cc, created FROM ${dbName}.customEV`,
+
+ `DROP TABLE ${dbName}.customEV`,
+ `RENAME TABLE ${dbName}.customEV_temp TO ${dbName}.customEV`,
+]
+
+queriesRunner(queries)