fix migrations
This commit is contained in:
@@ -1,28 +1,6 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "performance" (
|
||||
"performance_id" UUID NOT NULL,
|
||||
"website_id" UUID NOT NULL,
|
||||
"session_id" UUID NOT NULL,
|
||||
"visit_id" UUID NOT NULL,
|
||||
"url_path" VARCHAR(500) NOT NULL,
|
||||
"lcp" DECIMAL(10,1),
|
||||
"inp" DECIMAL(10,1),
|
||||
"cls" DECIMAL(10,4),
|
||||
"fcp" DECIMAL(10,1),
|
||||
"ttfb" DECIMAL(10,1),
|
||||
"created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "performance_pkey" PRIMARY KEY ("performance_id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "performance_website_id_idx" ON "performance"("website_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "performance_session_id_idx" ON "performance"("session_id");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "performance_website_id_created_at_idx" ON "performance"("website_id", "created_at");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "performance_website_id_url_path_created_at_idx" ON "performance"("website_id", "url_path", "created_at");
|
||||
-- AlterTable
|
||||
ALTER TABLE "website_event" ADD COLUMN "cls" DECIMAL(10,4),
|
||||
ADD COLUMN "fcp" DECIMAL(10,1),
|
||||
ADD COLUMN "inp" DECIMAL(10,1),
|
||||
ADD COLUMN "lcp" DECIMAL(10,1),
|
||||
ADD COLUMN "ttfb" DECIMAL(10,1);
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
ALTER TABLE "session_replay"
|
||||
ADD COLUMN IF NOT EXISTS "visit_id" UUID;
|
||||
|
||||
UPDATE "session_replay" AS sr
|
||||
SET "visit_id" = we."visit_id"
|
||||
FROM (
|
||||
SELECT DISTINCT ON ("website_id", "session_id")
|
||||
"website_id",
|
||||
"session_id",
|
||||
"visit_id"
|
||||
FROM "website_event"
|
||||
WHERE "visit_id" IS NOT NULL
|
||||
ORDER BY "website_id", "session_id", "created_at" DESC
|
||||
) AS we
|
||||
WHERE sr."visit_id" IS NULL
|
||||
AND sr."website_id" = we."website_id"
|
||||
AND sr."session_id" = we."session_id";
|
||||
|
||||
UPDATE "session_replay"
|
||||
SET "visit_id" = (
|
||||
substr(md5("session_id"::text || ':' || "chunk_index"::text), 1, 8) ||
|
||||
'-' ||
|
||||
substr(md5("session_id"::text || ':' || "chunk_index"::text), 9, 4) ||
|
||||
'-' ||
|
||||
substr(md5("session_id"::text || ':' || "chunk_index"::text), 13, 4) ||
|
||||
'-' ||
|
||||
substr(md5("session_id"::text || ':' || "chunk_index"::text), 17, 4) ||
|
||||
'-' ||
|
||||
substr(md5("session_id"::text || ':' || "chunk_index"::text), 21, 12)
|
||||
)::uuid
|
||||
WHERE "visit_id" IS NULL;
|
||||
|
||||
ALTER TABLE "session_replay"
|
||||
ALTER COLUMN "visit_id" SET NOT NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "session_replay_visit_id_idx" ON "session_replay"("visit_id");
|
||||
+5
-26
@@ -47,7 +47,6 @@ model Session {
|
||||
|
||||
websiteEvents WebsiteEvent[]
|
||||
sessionData SessionData[]
|
||||
performance Performance[]
|
||||
revenue Revenue[]
|
||||
|
||||
@@index([createdAt])
|
||||
@@ -83,7 +82,6 @@ model Website {
|
||||
createUser User? @relation("createUser", fields: [createdBy], references: [id])
|
||||
team Team? @relation(fields: [teamId], references: [id])
|
||||
eventData EventData[]
|
||||
performance Performance[]
|
||||
reports Report[]
|
||||
revenue Revenue[]
|
||||
segments Segment[]
|
||||
@@ -124,6 +122,11 @@ model WebsiteEvent {
|
||||
eventName String? @map("event_name") @db.VarChar(50)
|
||||
tag String? @db.VarChar(50)
|
||||
hostname String? @db.VarChar(100)
|
||||
lcp Decimal? @db.Decimal(10, 1)
|
||||
inp Decimal? @db.Decimal(10, 1)
|
||||
cls Decimal? @db.Decimal(10, 4)
|
||||
fcp Decimal? @db.Decimal(10, 1)
|
||||
ttfb Decimal? @db.Decimal(10, 1)
|
||||
|
||||
eventData EventData[]
|
||||
session Session @relation(fields: [sessionId], references: [id])
|
||||
@@ -343,30 +346,6 @@ model Board {
|
||||
@@index([createdAt])
|
||||
@@map("board")
|
||||
}
|
||||
|
||||
model Performance {
|
||||
id String @id() @map("performance_id") @db.Uuid
|
||||
websiteId String @map("website_id") @db.Uuid
|
||||
sessionId String @map("session_id") @db.Uuid
|
||||
visitId String @map("visit_id") @db.Uuid
|
||||
urlPath String @map("url_path") @db.VarChar(500)
|
||||
lcp Decimal? @db.Decimal(10, 1)
|
||||
inp Decimal? @db.Decimal(10, 1)
|
||||
cls Decimal? @db.Decimal(10, 4)
|
||||
fcp Decimal? @db.Decimal(10, 1)
|
||||
ttfb Decimal? @db.Decimal(10, 1)
|
||||
createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6)
|
||||
|
||||
website Website @relation(fields: [websiteId], references: [id])
|
||||
session Session @relation(fields: [sessionId], references: [id])
|
||||
|
||||
@@index([websiteId])
|
||||
@@index([sessionId])
|
||||
@@index([websiteId, createdAt])
|
||||
@@index([websiteId, urlPath, createdAt])
|
||||
@@map("performance")
|
||||
}
|
||||
|
||||
model Share {
|
||||
id String @id() @map("share_id") @db.Uuid
|
||||
entityId String @map("entity_id") @db.Uuid
|
||||
|
||||
Reference in New Issue
Block a user