From 76519e0d14c996913c1ddd75db6a95f4d36f68b6 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Wed, 4 Jun 2025 09:27:28 -0700 Subject: [PATCH] add segment and report param migrations --- .../migrations/11_add_segment/migration.sql | 17 +++++++++ .../12_update_report_parameter/migration.sql | 3 ++ db/postgresql/schema.prisma | 35 +++++++++++++------ 3 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 db/postgresql/migrations/11_add_segment/migration.sql create mode 100644 db/postgresql/migrations/12_update_report_parameter/migration.sql diff --git a/db/postgresql/migrations/11_add_segment/migration.sql b/db/postgresql/migrations/11_add_segment/migration.sql new file mode 100644 index 00000000..7fbb0867 --- /dev/null +++ b/db/postgresql/migrations/11_add_segment/migration.sql @@ -0,0 +1,17 @@ +-- CreateTable +CREATE TABLE "segment" ( + "segment_id" UUID NOT NULL, + "website_id" UUID NOT NULL, + "name" VARCHAR(200) NOT NULL, + "filters" JSONB NOT NULL, + "created_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP, + "updated_at" TIMESTAMPTZ(6), + + CONSTRAINT "segment_pkey" PRIMARY KEY ("segment_id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "segment_segment_id_key" ON "segment"("segment_id"); + +-- CreateIndex +CREATE INDEX "segment_website_id_idx" ON "segment"("website_id"); diff --git a/db/postgresql/migrations/12_update_report_parameter/migration.sql b/db/postgresql/migrations/12_update_report_parameter/migration.sql new file mode 100644 index 00000000..f063973a --- /dev/null +++ b/db/postgresql/migrations/12_update_report_parameter/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "report" +ALTER COLUMN "parameters" SET DATA TYPE JSONB USING parameters::JSONB diff --git a/db/postgresql/schema.prisma b/db/postgresql/schema.prisma index 69efa265..a6c35908 100644 --- a/db/postgresql/schema.prisma +++ b/db/postgresql/schema.prisma @@ -77,6 +77,7 @@ model Website { eventData EventData[] report Report[] sessionData SessionData[] + segment Segment[] @@index([userId]) @@index([teamId]) @@ -103,12 +104,12 @@ model WebsiteEvent { referrerQuery String? @map("referrer_query") @db.VarChar(500) referrerDomain String? @map("referrer_domain") @db.VarChar(500) pageTitle String? @map("page_title") @db.VarChar(500) - gclid String? @map("gclid") @db.VarChar(255) - fbclid String? @map("fbclid") @db.VarChar(255) - msclkid String? @map("msclkid") @db.VarChar(255) - ttclid String? @map("ttclid") @db.VarChar(255) + gclid String? @db.VarChar(255) + fbclid String? @db.VarChar(255) + msclkid String? @db.VarChar(255) + ttclid String? @db.VarChar(255) lifatid String? @map("li_fat_id") @db.VarChar(255) - twclid String? @map("twclid") @db.VarChar(255) + twclid String? @db.VarChar(255) eventType Int @default(1) @map("event_type") @db.Integer eventName String? @map("event_name") @db.VarChar(50) tag String? @db.VarChar(50) @@ -199,7 +200,7 @@ model TeamUser { id String @id() @unique() @map("team_user_id") @db.Uuid teamId String @map("team_id") @db.Uuid userId String @map("user_id") @db.Uuid - role String @map("role") @db.VarChar(50) + role String @db.VarChar(50) createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6) updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6) @@ -215,10 +216,10 @@ model Report { id String @id() @unique() @map("report_id") @db.Uuid userId String @map("user_id") @db.Uuid websiteId String @map("website_id") @db.Uuid - type String @map("type") @db.VarChar(200) - name String @map("name") @db.VarChar(200) - description String @map("description") @db.VarChar(500) - parameters String @map("parameters") @db.VarChar(6000) + type String @db.VarChar(200) + name String @db.VarChar(200) + description String @db.VarChar(500) + parameters Json createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6) updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6) @@ -231,3 +232,17 @@ model Report { @@index([name]) @@map("report") } + +model Segment { + id String @id() @unique() @map("segment_id") @db.Uuid + websiteId String @map("website_id") @db.Uuid + name String @db.VarChar(200) + filters Json + createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6) + updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6) + + website Website @relation(fields: [websiteId], references: [id]) + + @@index([websiteId]) + @@map("segment") +} \ No newline at end of file