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!

low cardinality for captcha

Blue Mouseb7c82476bf58
diff --git a/migrations/clickhouse/2023_05_07.js b/migrations/clickhouse/2023_05_07.js
new file mode 100644
index 000000000..844158130
--- /dev/null
+++ b/migrations/clickhouse/2023_05_07.js
@@ -0,0 +1,26 @@
+const { queriesRunner, dbName } = require('./setup')
+
+const queries = [
+ `DROP TABLE IF EXISTS ${dbName}.captcha_temp`,
+ `CREATE TABLE IF NOT EXISTS ${dbName}.captcha_temp
+ (
+ pid FixedString(12),
+ dv LowCardinality(Nullable(String)),
+ br LowCardinality(Nullable(String)),
+ os Nullable(String),
+ cc Nullable(FixedString(2)),
+ manuallyPassed UInt8,
+ created DateTime
+ )
+ ENGINE = MergeTree()
+ PARTITION BY toYYYYMM(created)
+ ORDER BY (pid, created)`
+
+ `INSERT INTO ${dbName}.captcha_temp (pid, dv, br, os, cc, manuallyPassed, created)
+ SELECT pid, dv, br, os, cc, manuallyPassed, created 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 bca8e42a8..f40aa5bdc 100644
--- a/migrations/clickhouse/initialise_database.js
+++ b/migrations/clickhouse/initialise_database.js
@@ -72,6 +72,21 @@ const CLICKHOUSE_INIT_QUERIES = [
ENGINE = MergeTree()
PARTITION BY toYYYYMM(created)
ORDER BY (pid, created);`,
+
+ // The CAPTCHA data table
+ `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
+ )
+ ENGINE = MergeTree()
+ PARTITION BY toYYYYMM(created)
+ ORDER BY (pid, created);`
]
const initialiseDatabase = async () => {