Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Added access_code column to teams.

Mike Caoaef7326f4c3a
diff --git a/db/postgresql/migrations/02_add_access_code/migration.sql b/db/postgresql/migrations/02_add_access_code/migration.sql
new file mode 100644
index 000000000..9f27d6148
--- /dev/null
+++ b/db/postgresql/migrations/02_add_access_code/migration.sql
@@ -0,0 +1,27 @@
+/*
+ Warnings:
+
+ - You are about to alter the column `share_id` on the `website` table. The data in that column could be lost. The data in that column will be cast from `VarChar(64)` to `VarChar(50)`.
+ - A unique constraint covering the columns `[access_code]` on the table `team` will be added. If there are existing duplicate values, this will fail.
+
+*/
+-- AlterTable
+ALTER TABLE "team" ADD COLUMN "access_code" VARCHAR(50);
+
+-- AlterTable
+ALTER TABLE "website" ALTER COLUMN "share_id" SET DATA TYPE VARCHAR(50);
+
+-- CreateIndex
+CREATE UNIQUE INDEX "team_access_code_key" ON "team"("access_code");
+
+-- CreateIndex
+CREATE INDEX "team_user_id_idx" ON "team"("user_id");
+
+-- CreateIndex
+CREATE INDEX "team_access_code_idx" ON "team"("access_code");
+
+-- CreateIndex
+CREATE INDEX "team_user_team_id_idx" ON "team_user"("team_id");
+
+-- CreateIndex
+CREATE INDEX "team_user_user_id_idx" ON "team_user"("user_id");
diff --git a/db/postgresql/schema.prisma b/db/postgresql/schema.prisma
index df273edf2..5a084865d 100644
--- a/db/postgresql/schema.prisma
+++ b/db/postgresql/schema.prisma
@@ -43,7 +43,7 @@ model Website {
id String @id @unique @map("website_id") @db.Uuid
name String @db.VarChar(100)
domain String? @db.VarChar(500)
- shareId String? @unique @map("share_id") @db.VarChar(64)
+ shareId String? @unique @map("share_id") @db.VarChar(50)
revId Int @default(0) @map("rev_id") @db.Integer
userId String? @map("user_id") @db.Uuid
teamId String? @map("team_id") @db.Uuid
@@ -79,16 +79,19 @@ model WebsiteEvent {
}
model Team {
- id String @id() @unique() @map("team_id") @db.Uuid
- name String @db.VarChar(50)
- userId String @map("user_id") @db.Uuid
- createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
- updatedAt DateTime? @map("updated_at") @db.Timestamptz(6)
- deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
+ id String @id() @unique() @map("team_id") @db.Uuid
+ name String @db.VarChar(50)
+ userId String @map("user_id") @db.Uuid
+ accessCode String? @unique @map("access_code") @db.VarChar(50)
+ createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
+ updatedAt DateTime? @map("updated_at") @db.Timestamptz(6)
+ deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
teamUsers TeamUser[]
Website Website[]
+ @@index([userId])
+ @@index([accessCode])
@@map("team")
}
@@ -104,5 +107,7 @@ model TeamUser {
team Team @relation(fields: [teamId], references: [id])
user User @relation(fields: [userId], references: [id])
+ @@index([teamId])
+ @@index([userId])
@@map("team_user")
}
diff --git a/lib/clickhouse.js b/lib/clickhouse.js
index df7af0659..786763713 100644
--- a/lib/clickhouse.js
+++ b/lib/clickhouse.js
@@ -204,7 +204,7 @@ async function findFirst(data) {
}
async function connect() {
- if (!clickhouse) {
+ if (enabled && !clickhouse) {
clickhouse = process.env.CLICKHOUSE_URL && (global[CLICKHOUSE] || getClient());
}