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 user update logic & added error logging for selfhosted

Blue Mouse4ae90b782e02
diff --git a/apps/selfhosted/src/common/utils.ts b/apps/selfhosted/src/common/utils.ts
index 33cd7ec16..90fd4d3e6 100644
--- a/apps/selfhosted/src/common/utils.ts
+++ b/apps/selfhosted/src/common/utils.ts
@@ -25,6 +25,7 @@ import {
isDevelopment,
isProxiedByCloudflare,
} from './constants'
+import { DEFAULT_TIMEZONE, TimeFormat } from '../user/entities/user.entity'
import { Project } from '../project/entity/project.entity'
dayjs.extend(utc)
@@ -241,7 +242,12 @@ const updateUserClickhouse = async (user: IClickhouseUser) => {
const userExists = await userClickhouseExists()
if (!userExists) {
- await createUserClickhouse(user)
+ await createUserClickhouse({
+ timezone: DEFAULT_TIMEZONE,
+ timeFormat: TimeFormat['12-hour'],
+ showLiveVisitorsInTitle: 0,
+ ...user,
+ })
}
const paramsData = {
diff --git a/apps/selfhosted/src/user/user.controller.ts b/apps/selfhosted/src/user/user.controller.ts
index d136a4f1f..060eb0de1 100644
--- a/apps/selfhosted/src/user/user.controller.ts
+++ b/apps/selfhosted/src/user/user.controller.ts
@@ -51,7 +51,11 @@ export class UserController {
await updateUserClickhouse({
showLiveVisitorsInTitle: Number(show),
})
- } catch (_) {
+ } catch (reason) {
+ console.error(
+ '[ERROR](setShowLiveVisitors) Failed to update current user',
+ reason,
+ )
throw new BadRequestException(
'An error occurred while updating live visitors user setting',
)
@@ -84,7 +88,11 @@ export class UserController {
...user,
...settings,
}
- } catch (_) {
+ } catch (reason) {
+ console.error(
+ '[ERROR](updateCurrentUser) Failed to update current user',
+ reason,
+ )
throw new BadRequestException('An error occurred while updating user')
}
}
diff --git a/migrations/clickhouse/initialise_selfhosted.js b/migrations/clickhouse/initialise_selfhosted.js
index 81eba743b..17238a469 100644
--- a/migrations/clickhouse/initialise_selfhosted.js
+++ b/migrations/clickhouse/initialise_selfhosted.js
@@ -30,7 +30,7 @@ const CLICKHOUSE_INIT_QUERIES = [
id String,
timezone Nullable(String),
timeFormat Nullable(String),
- showLiveVisitorsInTitle Int8
+ showLiveVisitorsInTitle Nullable(Int8)
)
ENGINE = MergeTree()
PRIMARY KEY id;`,
diff --git a/migrations/clickhouse/selfhosted_2023_10_11.js b/migrations/clickhouse/selfhosted_2023_10_11.js
new file mode 100644
index 000000000..1275bd507
--- /dev/null
+++ b/migrations/clickhouse/selfhosted_2023_10_11.js
@@ -0,0 +1,23 @@
+const { queriesRunner, dbName } = require('./setup')
+
+const queries = [
+ // Added 'showLiveVisitorsInTitle' column
+ `DROP TABLE IF EXISTS ${dbName}.sfuser_temp`,
+ `CREATE TABLE IF NOT EXISTS ${dbName}.sfuser_temp
+ (
+ id String,
+ timezone Nullable(String),
+ timeFormat Nullable(String),
+ showLiveVisitorsInTitle Nullable(Int8)
+ )
+ ENGINE = MergeTree()
+ PRIMARY KEY id;`,
+
+ `INSERT INTO ${dbName}.sfuser_temp (*)
+ SELECT id, timezone, timeFormat, showLiveVisitorsInTitle FROM ${dbName}.sfuser`,
+
+ `DROP TABLE ${dbName}.sfuser`,
+ `RENAME TABLE ${dbName}.sfuser_temp TO ${dbName}.sfuser`,
+]
+
+queriesRunner(queries)