mirror of
https://github.com/umami-software/umami.git
synced 2026-02-18 19:45:35 +01:00
Merge branch 'umami-software:master' into master
This commit is contained in:
commit
8776b22b94
257 changed files with 4432 additions and 2916 deletions
90
db/clickhouse/migrations/02_add_visit_id.sql
Normal file
90
db/clickhouse/migrations/02_add_visit_id.sql
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
CREATE TABLE umami.website_event_join
|
||||
(
|
||||
session_id UUID,
|
||||
visit_id UUID,
|
||||
created_at DateTime('UTC')
|
||||
)
|
||||
engine = MergeTree
|
||||
ORDER BY (session_id, created_at)
|
||||
SETTINGS index_granularity = 8192;
|
||||
|
||||
INSERT INTO umami.website_event_join
|
||||
SELECT DISTINCT
|
||||
s.session_id,
|
||||
generateUUIDv4() visit_id,
|
||||
s.created_at
|
||||
FROM (SELECT DISTINCT session_id,
|
||||
date_trunc('hour', created_at) created_at
|
||||
FROM website_event) s;
|
||||
|
||||
-- create new table
|
||||
CREATE TABLE umami.website_event_new
|
||||
(
|
||||
website_id UUID,
|
||||
session_id UUID,
|
||||
visit_id UUID,
|
||||
event_id UUID,
|
||||
hostname LowCardinality(String),
|
||||
browser LowCardinality(String),
|
||||
os LowCardinality(String),
|
||||
device LowCardinality(String),
|
||||
screen LowCardinality(String),
|
||||
language LowCardinality(String),
|
||||
country LowCardinality(String),
|
||||
subdivision1 LowCardinality(String),
|
||||
subdivision2 LowCardinality(String),
|
||||
city String,
|
||||
url_path String,
|
||||
url_query String,
|
||||
referrer_path String,
|
||||
referrer_query String,
|
||||
referrer_domain String,
|
||||
page_title String,
|
||||
event_type UInt32,
|
||||
event_name String,
|
||||
created_at DateTime('UTC'),
|
||||
job_id UUID
|
||||
)
|
||||
engine = MergeTree
|
||||
ORDER BY (website_id, session_id, created_at)
|
||||
SETTINGS index_granularity = 8192;
|
||||
|
||||
INSERT INTO umami.website_event_new
|
||||
SELECT we.website_id,
|
||||
we.session_id,
|
||||
j.visit_id,
|
||||
we.event_id,
|
||||
we.hostname,
|
||||
we.browser,
|
||||
we.os,
|
||||
we.device,
|
||||
we.screen,
|
||||
we.language,
|
||||
we.country,
|
||||
we.subdivision1,
|
||||
we.subdivision2,
|
||||
we.city,
|
||||
we.url_path,
|
||||
we.url_query,
|
||||
we.referrer_path,
|
||||
we.referrer_query,
|
||||
we.referrer_domain,
|
||||
we.page_title,
|
||||
we.event_type,
|
||||
we.event_name,
|
||||
we.created_at,
|
||||
we.job_id
|
||||
FROM umami.website_event we
|
||||
JOIN umami.website_event_join j
|
||||
ON we.session_id = j.session_id
|
||||
and date_trunc('hour', we.created_at) = j.created_at
|
||||
|
||||
RENAME TABLE umami.website_event TO umami.website_event_old;
|
||||
RENAME TABLE umami.website_event_new TO umami.website_event;
|
||||
|
||||
/*
|
||||
|
||||
DROP TABLE umami.website_event_old
|
||||
DROP TABLE umami.website_event_join
|
||||
|
||||
*/
|
||||
|
|
@ -3,6 +3,7 @@ CREATE TABLE umami.website_event
|
|||
(
|
||||
website_id UUID,
|
||||
session_id UUID,
|
||||
visit_id UUID,
|
||||
event_id UUID,
|
||||
--sessions
|
||||
hostname LowCardinality(String),
|
||||
|
|
|
|||
22
db/mysql/migrations/05_add_visit_id/migration.sql
Normal file
22
db/mysql/migrations/05_add_visit_id/migration.sql
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE `website_event` ADD COLUMN `visit_id` VARCHAR(36) NULL;
|
||||
|
||||
UPDATE `website_event` we
|
||||
JOIN (SELECT DISTINCT
|
||||
s.session_id,
|
||||
s.visit_time,
|
||||
BIN_TO_UUID(RANDOM_BYTES(16) & 0xffffffffffff0fff3fffffffffffffff | 0x00000000000040008000000000000000) uuid
|
||||
FROM (SELECT DISTINCT session_id,
|
||||
DATE_FORMAT(created_at, '%Y-%m-%d %H:00:00') visit_time
|
||||
FROM `website_event`) s) a
|
||||
ON we.session_id = a.session_id and DATE_FORMAT(we.created_at, '%Y-%m-%d %H:00:00') = a.visit_time
|
||||
SET we.visit_id = a.uuid
|
||||
WHERE we.visit_id IS NULL;
|
||||
|
||||
ALTER TABLE `website_event` MODIFY `visit_id` VARCHAR(36) NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX `website_event_visit_id_idx` ON `website_event`(`visit_id`);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX `website_event_website_id_visit_id_created_at_idx` ON `website_event`(`website_id`, `visit_id`, `created_at`);
|
||||
|
|
@ -92,6 +92,7 @@ model WebsiteEvent {
|
|||
id String @id() @map("event_id") @db.VarChar(36)
|
||||
websiteId String @map("website_id") @db.VarChar(36)
|
||||
sessionId String @map("session_id") @db.VarChar(36)
|
||||
visitId String @map("visit_id") @db.VarChar(36)
|
||||
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0)
|
||||
urlPath String @map("url_path") @db.VarChar(500)
|
||||
urlQuery String? @map("url_query") @db.VarChar(500)
|
||||
|
|
@ -107,6 +108,7 @@ model WebsiteEvent {
|
|||
|
||||
@@index([createdAt])
|
||||
@@index([sessionId])
|
||||
@@index([visitId])
|
||||
@@index([websiteId])
|
||||
@@index([websiteId, createdAt])
|
||||
@@index([websiteId, createdAt, urlPath])
|
||||
|
|
@ -115,6 +117,7 @@ model WebsiteEvent {
|
|||
@@index([websiteId, createdAt, pageTitle])
|
||||
@@index([websiteId, createdAt, eventName])
|
||||
@@index([websiteId, sessionId, createdAt])
|
||||
@@index([websiteId, visitId, createdAt])
|
||||
@@map("website_event")
|
||||
}
|
||||
|
||||
|
|
|
|||
22
db/postgresql/migrations/05_add_visit_id/migration.sql
Normal file
22
db/postgresql/migrations/05_add_visit_id/migration.sql
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
-- AlterTable
|
||||
ALTER TABLE "website_event" ADD COLUMN "visit_id" UUID NULL;
|
||||
|
||||
UPDATE "website_event" we
|
||||
SET visit_id = a.uuid
|
||||
FROM (SELECT DISTINCT
|
||||
s.session_id,
|
||||
s.visit_time,
|
||||
gen_random_uuid() uuid
|
||||
FROM (SELECT DISTINCT session_id,
|
||||
date_trunc('hour', created_at) visit_time
|
||||
FROM "website_event") s) a
|
||||
WHERE we.session_id = a.session_id
|
||||
and date_trunc('hour', we.created_at) = a.visit_time;
|
||||
|
||||
ALTER TABLE "website_event" ALTER COLUMN "visit_id" SET NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "website_event_visit_id_idx" ON "website_event"("visit_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "website_event_website_id_visit_id_created_at_idx" ON "website_event"("website_id", "visit_id", "created_at");
|
||||
|
|
@ -93,6 +93,7 @@ model WebsiteEvent {
|
|||
id String @id() @map("event_id") @db.Uuid
|
||||
websiteId String @map("website_id") @db.Uuid
|
||||
sessionId String @map("session_id") @db.Uuid
|
||||
visitId String @map("visit_id") @db.Uuid
|
||||
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
urlPath String @map("url_path") @db.VarChar(500)
|
||||
urlQuery String? @map("url_query") @db.VarChar(500)
|
||||
|
|
@ -108,6 +109,7 @@ model WebsiteEvent {
|
|||
|
||||
@@index([createdAt])
|
||||
@@index([sessionId])
|
||||
@@index([visitId])
|
||||
@@index([websiteId])
|
||||
@@index([websiteId, createdAt])
|
||||
@@index([websiteId, createdAt, urlPath])
|
||||
|
|
@ -116,6 +118,7 @@ model WebsiteEvent {
|
|||
@@index([websiteId, createdAt, pageTitle])
|
||||
@@index([websiteId, createdAt, eventName])
|
||||
@@index([websiteId, sessionId, createdAt])
|
||||
@@index([websiteId, visitId, createdAt])
|
||||
@@map("website_event")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue