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!

fixed migration

Blue Mouseea55eb0fd2c6
diff --git a/migrations/clickhouse/2022_12_24.js b/migrations/clickhouse/2022_12_24.js
index 1ccd33a3d..66b91b906 100644
--- a/migrations/clickhouse/2022_12_24.js
+++ b/migrations/clickhouse/2022_12_24.js
@@ -1,6 +1,7 @@
const { queriesRunner, dbName } = require('./setup')
const queries = [
+ `DROP TABLE IF EXISTS ${dbName}.analytics_temp`,
`CREATE TABLE IF NOT EXISTS ${dbName}.analytics_temp
(
sId Nullable(String),
@@ -24,28 +25,8 @@ const queries = [
PARTITION BY toYYYYMM(created)
ORDER BY (pid, created);`,
- `INSERT INTO ${dbName}.analytics_temp (
- NULL,
- SELECT
- sId,
- pid,
- pg,
- dv,
- br,
- os,
- lc,
- ref,
- so,
- me,
- ca,
- lt,
- cc
- FROM ${dbName}.analytics,
- NULL,
- SELECT
- unique,
- created
- FROM ${dbName}.analytics)`,
+ `INSERT INTO ${dbName}.analytics_temp (sId, pid, pg, dv, br, os, lc, ref, so, me, ca, lt, cc, sdur, unique, created)
+ SELECT NULL, pid, pg, dv, br, os, lc, ref, so, me, ca, lt, cc, NULL, unique, created FROM ${dbName}.analytics`,
`DROP TABLE ${dbName}.analytics`,
`RENAME TABLE ${dbName}.analytics_temp TO ${dbName}.analytics`,
diff --git a/migrations/clickhouse/setup.js b/migrations/clickhouse/setup.js
index 30f18a44c..7730eb4ae 100644
--- a/migrations/clickhouse/setup.js
+++ b/migrations/clickhouse/setup.js
@@ -1,5 +1,6 @@
const { ClickHouse } = require('clickhouse')
const _ = require('lodash')
+const chalk = require('chalk')
require('dotenv').config()
const clickhouse = new ClickHouse({
@@ -22,14 +23,20 @@ const clickhouse = new ClickHouse({
})
const queriesRunner = async (queries) => {
+ let failed = false
for (const query of queries) {
+ if (failed) {
+ return
+ }
+
if (query) {
try {
await clickhouse.query(query).toPromise()
- console.log(`Query OK: ${query}`)
+ console.log(chalk.green('Query OK: '), query)
} catch (error) {
- console.error(`Query ERROR: ${query}`)
+ console.error(chalk.red('Query ERROR: '), query)
console.error(error)
+ failed = true
}
}
}
diff --git a/migrations/clickhouse/test_migration.js b/migrations/clickhouse/test_migration.js
new file mode 100644
index 000000000..35d8d3fdd
--- /dev/null
+++ b/migrations/clickhouse/test_migration.js
@@ -0,0 +1,7 @@
+const { queriesRunner, dbName } = require('./setup')
+
+const queries = [
+ `SELECT * FROM ${dbName}.analytics LIMIT 10`,
+]
+
+queriesRunner(queries)
diff --git a/package.json b/package.json
index ffe3b9400..6816feea3 100644
--- a/package.json
+++ b/package.json
@@ -36,6 +36,7 @@
"bcrypt": "^5.0.1",
"blake3": "^2.1.7",
"body-parser": "^1.20.0",
+ "chalk": "^4.1.2",
"class-transformer": "^0.5.1",
"class-validator": "^0.13.2",
"clickhouse": "^2.6.0",