From 1038a54fe4c46aa3edc0641dfa07c0c6c9aff411 Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Wed, 31 May 2023 12:01:16 -0700 Subject: [PATCH] add mysql 02 migration --- .../migrations/02_report_schema/migration.sql | 19 +++++++++++++++ db/mysql/schema.prisma | 23 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 db/mysql/migrations/02_report_schema/migration.sql diff --git a/db/mysql/migrations/02_report_schema/migration.sql b/db/mysql/migrations/02_report_schema/migration.sql new file mode 100644 index 00000000..0476e9f7 --- /dev/null +++ b/db/mysql/migrations/02_report_schema/migration.sql @@ -0,0 +1,19 @@ +-- CreateTable +CREATE TABLE `report` ( + `report_id` VARCHAR(36) NOT NULL, + `user_id` VARCHAR(36) NOT NULL, + `website_id` VARCHAR(36) NOT NULL, + `type` VARCHAR(200) NOT NULL, + `name` VARCHAR(200) NOT NULL, + `description` VARCHAR(500) NOT NULL, + `parameters` VARCHAR(6000) NOT NULL, + `created_at` TIMESTAMP(0) NULL DEFAULT CURRENT_TIMESTAMP(0), + `updated_at` TIMESTAMP(0) NULL, + + UNIQUE INDEX `report_report_id_key`(`report_id`), + INDEX `report_user_id_idx`(`user_id`), + INDEX `report_website_id_idx`(`website_id`), + INDEX `report_type_idx`(`type`), + INDEX `report_name_idx`(`name`), + PRIMARY KEY (`report_id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; diff --git a/db/mysql/schema.prisma b/db/mysql/schema.prisma index 6455c8c0..0752f418 100644 --- a/db/mysql/schema.prisma +++ b/db/mysql/schema.prisma @@ -19,6 +19,7 @@ model User { website Website[] teamUser TeamUser[] + Report Report[] @@map("user") } @@ -59,6 +60,7 @@ model Website { user User? @relation(fields: [userId], references: [id]) teamWebsite TeamWebsite[] eventData EventData[] + Report Report[] @@index([userId]) @@index([createdAt]) @@ -155,3 +157,24 @@ model TeamWebsite { @@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) + websiteId String @map("website_id") @db.VarChar(36) + 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) + createdAt DateTime? @default(now()) @map("created_at") @db.Timestamp(0) + updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamp(0) + + user User @relation(fields: [userId], references: [id]) + website Website @relation(fields: [websiteId], references: [id]) + + @@index([userId]) + @@index([websiteId]) + @@index([type]) + @@index([name]) + @@map("report") +} \ No newline at end of file