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(), })