From 2ce5597dfe1c51cbec86c13b1b6a3fe5eecf2e53 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Sat, 13 Jul 2024 16:32:03 +0800 Subject: [PATCH] refactor: change feed channel notifyFrequency type to enum --- .../migration.sql | 12 ++++++++++++ src/server/prisma/schema.prisma | 17 ++++++++++++----- src/server/prisma/zod/feedchannel.ts | 3 ++- 3 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 src/server/prisma/migrations/20240713082513_update_feed_channel_frequency_to_enum/migration.sql diff --git a/src/server/prisma/migrations/20240713082513_update_feed_channel_frequency_to_enum/migration.sql b/src/server/prisma/migrations/20240713082513_update_feed_channel_frequency_to_enum/migration.sql new file mode 100644 index 0000000..a3dfbb5 --- /dev/null +++ b/src/server/prisma/migrations/20240713082513_update_feed_channel_frequency_to_enum/migration.sql @@ -0,0 +1,12 @@ +/* + Warnings: + + - The `notifyFrequency` column on the `FeedChannel` table would be dropped and recreated. This will lead to data loss if there is data in the column. + +*/ +-- CreateEnum +CREATE TYPE "FeedChannelNotifyFrequency" AS ENUM ('event', 'day', 'week', 'month'); + +-- AlterTable +ALTER TABLE "FeedChannel" DROP COLUMN "notifyFrequency", +ADD COLUMN "notifyFrequency" "FeedChannelNotifyFrequency" NOT NULL DEFAULT 'day'; diff --git a/src/server/prisma/schema.prisma b/src/server/prisma/schema.prisma index a6c25c8..207162f 100644 --- a/src/server/prisma/schema.prisma +++ b/src/server/prisma/schema.prisma @@ -446,13 +446,20 @@ model SurveyResult { @@index([sessionId]) } +enum FeedChannelNotifyFrequency { + event + day + week + month +} + model FeedChannel { - id String @id @default(cuid()) @db.VarChar(30) - workspaceId String @db.VarChar(30) + id String @id @default(cuid()) @db.VarChar(30) + workspaceId String @db.VarChar(30) name String - notifyFrequency String @default("day") - createdAt DateTime @default(now()) @db.Timestamptz(6) - updatedAt DateTime @updatedAt @db.Timestamptz(6) + notifyFrequency FeedChannelNotifyFrequency @default(day) + createdAt DateTime @default(now()) @db.Timestamptz(6) + updatedAt DateTime @updatedAt @db.Timestamptz(6) workspace Workspace @relation(fields: [workspaceId], references: [id], onUpdate: Cascade, onDelete: Cascade) events FeedEvent[] diff --git a/src/server/prisma/zod/feedchannel.ts b/src/server/prisma/zod/feedchannel.ts index e4eb07d..4e2c601 100644 --- a/src/server/prisma/zod/feedchannel.ts +++ b/src/server/prisma/zod/feedchannel.ts @@ -1,12 +1,13 @@ import * as z from "zod" import * as imports from "./schemas" +import { FeedChannelNotifyFrequency } from "@prisma/client" import { CompleteWorkspace, RelatedWorkspaceModelSchema, CompleteFeedEvent, RelatedFeedEventModelSchema, CompleteNotification, RelatedNotificationModelSchema } from "./index" export const FeedChannelModelSchema = z.object({ id: z.string(), workspaceId: z.string(), name: z.string(), - notifyFrequency: z.string(), + notifyFrequency: z.nativeEnum(FeedChannelNotifyFrequency), createdAt: z.date(), updatedAt: z.date(), })