From a6a73db9c456f226dab9890eaee03cd4db62f0a7 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Tue, 16 Jan 2024 12:32:27 -0800 Subject: [PATCH] update schema file and add migrations --- .../migrations/04_team_redesign/migration.sql | 17 +++++++++++++++ db/mysql/schema.prisma | 21 +++++-------------- .../migrations/04_team_redesign/migration.sql | 17 +++++++++++++++ db/postgresql/schema.prisma | 21 +++++-------------- 4 files changed, 44 insertions(+), 32 deletions(-) create mode 100644 db/mysql/migrations/04_team_redesign/migration.sql create mode 100644 db/postgresql/migrations/04_team_redesign/migration.sql diff --git a/db/mysql/migrations/04_team_redesign/migration.sql b/db/mysql/migrations/04_team_redesign/migration.sql new file mode 100644 index 00000000..1ff7ee6e --- /dev/null +++ b/db/mysql/migrations/04_team_redesign/migration.sql @@ -0,0 +1,17 @@ +/* + Warnings: + + - You are about to drop the `team_website` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- AlterTable +ALTER TABLE `team` ADD COLUMN `deleted_at` TIMESTAMP(0) NULL; + +-- AlterTable +ALTER TABLE `website` ADD COLUMN `team_id` VARCHAR(36) NULL; + +-- DropTable +DROP TABLE `team_website`; + +-- CreateIndex +CREATE INDEX `website_team_id_idx` ON `website`(`team_id`); diff --git a/db/mysql/schema.prisma b/db/mysql/schema.prisma index 38bb91f4..de1a3f7f 100644 --- a/db/mysql/schema.prisma +++ b/db/mysql/schema.prisma @@ -64,17 +64,19 @@ model Website { shareId String? @unique @map("share_id") @db.VarChar(50) resetAt DateTime? @map("reset_at") @db.Timestamp(0) userId String? @map("user_id") @db.VarChar(36) + teamId String? @map("team_id") @db.VarChar(36) createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0) updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamp(0) deletedAt DateTime? @map("deleted_at") @db.Timestamp(0) user User? @relation(fields: [userId], references: [id]) - teamWebsite TeamWebsite[] + team Team? @relation(fields: [teamId], references: [id]) eventData EventData[] report Report[] sessionData SessionData[] @@index([userId]) + @@index([teamId]) @@index([createdAt]) @@index([shareId]) @@map("website") @@ -159,9 +161,10 @@ model Team { accessCode String? @unique @map("access_code") @db.VarChar(50) createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0) updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamp(0) + deletedAt DateTime? @map("deleted_at") @db.Timestamp(0) + website Website[] teamUser TeamUser[] - teamWebsite TeamWebsite[] @@index([accessCode]) @@map("team") @@ -183,20 +186,6 @@ model TeamUser { @@map("team_user") } -model TeamWebsite { - id String @id() @unique() @map("team_website_id") @db.VarChar(36) - teamId String @map("team_id") @db.VarChar(36) - websiteId String @map("website_id") @db.VarChar(36) - createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0) - - team Team @relation(fields: [teamId], references: [id]) - website Website @relation(fields: [websiteId], references: [id]) - - @@index([teamId]) - @@index([websiteId]) - @@map("team_website") -} - model Report { id String @id() @unique() @map("report_id") @db.VarChar(36) userId String @map("user_id") @db.VarChar(36) diff --git a/db/postgresql/migrations/04_team_redesign/migration.sql b/db/postgresql/migrations/04_team_redesign/migration.sql new file mode 100644 index 00000000..d69e371f --- /dev/null +++ b/db/postgresql/migrations/04_team_redesign/migration.sql @@ -0,0 +1,17 @@ +/* + Warnings: + + - You are about to drop the `team_website` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- AlterTable +ALTER TABLE "team" ADD COLUMN "deleted_at" TIMESTAMPTZ(6) DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "website" ADD COLUMN "team_id" UUID; + +-- DropTable +DROP TABLE "team_website"; + +-- CreateIndex +CREATE INDEX "website_team_id_idx" ON "website"("team_id"); diff --git a/db/postgresql/schema.prisma b/db/postgresql/schema.prisma index 336e8f50..6dda2b02 100644 --- a/db/postgresql/schema.prisma +++ b/db/postgresql/schema.prisma @@ -65,17 +65,19 @@ model Website { shareId String? @unique @map("share_id") @db.VarChar(50) resetAt DateTime? @map("reset_at") @db.Timestamptz(6) userId String? @map("user_id") @db.Uuid + teamId String? @map("team_id") @db.Uuid createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6) updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6) deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6) user User? @relation(fields: [userId], references: [id]) - teamWebsite TeamWebsite[] + team Team? @relation(fields: [teamId], references: [id]) eventData EventData[] report Report[] sessionData SessionData[] @@index([userId]) + @@index([teamId]) @@index([createdAt]) @@index([shareId]) @@map("website") @@ -160,9 +162,10 @@ model Team { accessCode String? @unique @map("access_code") @db.VarChar(50) createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6) updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6) + deletedAt DateTime? @default(now()) @map("deleted_at") @db.Timestamptz(6) + website Website[] teamUser TeamUser[] - teamWebsite TeamWebsite[] @@index([accessCode]) @@map("team") @@ -184,20 +187,6 @@ model TeamUser { @@map("team_user") } -model TeamWebsite { - id String @id() @unique() @map("team_website_id") @db.Uuid - teamId String @map("team_id") @db.Uuid - websiteId String @map("website_id") @db.Uuid - createdAt DateTime? @default(now()) @map("created_at") @db.Timestamptz(6) - - team Team @relation(fields: [teamId], references: [id]) - website Website @relation(fields: [websiteId], references: [id]) - - @@index([teamId]) - @@index([websiteId]) - @@map("team_website") -} - model Report { id String @id() @unique() @map("report_id") @db.Uuid userId String @map("user_id") @db.Uuid