mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-12 08:30:59 +01:00
update mysql migrations
This commit is contained in:
parent
b36d61609d
commit
af1a118374
21
db/mysql/migrations/05_add_visit_id/migration.sql
Normal file
21
db/mysql/migrations/05_add_visit_id/migration.sql
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "website_event" ADD COLUMN "visit_id" VARCHAR(36) NULL;
|
||||||
|
|
||||||
|
UPDATE "website_event" we
|
||||||
|
JOIN (SELECT 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 umami.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)
|
id String @id() @map("event_id") @db.VarChar(36)
|
||||||
websiteId String @map("website_id") @db.VarChar(36)
|
websiteId String @map("website_id") @db.VarChar(36)
|
||||||
sessionId String @map("session_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)
|
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0)
|
||||||
urlPath String @map("url_path") @db.VarChar(500)
|
urlPath String @map("url_path") @db.VarChar(500)
|
||||||
urlQuery String? @map("url_query") @db.VarChar(500)
|
urlQuery String? @map("url_query") @db.VarChar(500)
|
||||||
@ -107,6 +108,7 @@ model WebsiteEvent {
|
|||||||
|
|
||||||
@@index([createdAt])
|
@@index([createdAt])
|
||||||
@@index([sessionId])
|
@@index([sessionId])
|
||||||
|
@@index([visitId])
|
||||||
@@index([websiteId])
|
@@index([websiteId])
|
||||||
@@index([websiteId, createdAt])
|
@@index([websiteId, createdAt])
|
||||||
@@index([websiteId, createdAt, urlPath])
|
@@index([websiteId, createdAt, urlPath])
|
||||||
@ -115,6 +117,7 @@ model WebsiteEvent {
|
|||||||
@@index([websiteId, createdAt, pageTitle])
|
@@index([websiteId, createdAt, pageTitle])
|
||||||
@@index([websiteId, createdAt, eventName])
|
@@index([websiteId, createdAt, eventName])
|
||||||
@@index([websiteId, sessionId, createdAt])
|
@@index([websiteId, sessionId, createdAt])
|
||||||
|
@@index([websiteId, visitId, createdAt])
|
||||||
@@map("website_event")
|
@@map("website_event")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user