diff --git a/src/server/prisma/migrations/20240921130512_add_statuspage_incident/migration.sql b/src/server/prisma/migrations/20240921130512_add_statuspage_incident/migration.sql new file mode 100644 index 0000000..9d90444 --- /dev/null +++ b/src/server/prisma/migrations/20240921130512_add_statuspage_incident/migration.sql @@ -0,0 +1,10 @@ +-- CreateTable +CREATE TABLE "StatusPageIncident" ( + "id" VARCHAR(30) NOT NULL, + "createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMPTZ(6) NOT NULL, + "name" VARCHAR(100) NOT NULL, + "payload" JSON NOT NULL, + + CONSTRAINT "StatusPageIncident_pkey" PRIMARY KEY ("id") +); diff --git a/src/server/prisma/schema.prisma b/src/server/prisma/schema.prisma index 226e7a6..91ba191 100644 --- a/src/server/prisma/schema.prisma +++ b/src/server/prisma/schema.prisma @@ -436,6 +436,17 @@ model MonitorStatusPage { @@index([slug]) } +model StatusPageIncident { + id String @id @default(cuid()) @db.VarChar(30) + createdAt DateTime @default(now()) @db.Timestamptz(6) + updatedAt DateTime @updatedAt @db.Timestamptz(6) + name String @db.VarChar(100) + + /// [StatusPageIncidentPayload] + /// @zod.custom(imports.StatusPageIncidentPayloadSchema) + payload Json @db.Json +} + model WorkspaceDailyUsage { id String @id @unique @default(cuid()) @db.VarChar(30) workspaceId String @db.VarChar(30) diff --git a/src/server/prisma/zod/index.ts b/src/server/prisma/zod/index.ts index cbda417..e5c8086 100644 --- a/src/server/prisma/zod/index.ts +++ b/src/server/prisma/zod/index.ts @@ -19,6 +19,7 @@ export * from "./monitorevent.js" export * from "./monitordata.js" export * from "./monitorstatus.js" export * from "./monitorstatuspage.js" +export * from "./statuspageincident.js" export * from "./workspacedailyusage.js" export * from "./workspaceauditlog.js" export * from "./survey.js" diff --git a/src/server/prisma/zod/schemas/index.ts b/src/server/prisma/zod/schemas/index.ts index 6a3c8d9..6d33555 100644 --- a/src/server/prisma/zod/schemas/index.ts +++ b/src/server/prisma/zod/schemas/index.ts @@ -19,3 +19,26 @@ export const SurveyPayloadSchema = z.object({ }) ), }); + +export const StatusPageIncidentPayloadSchema = z.object({ + history: z.array( + z.object({ + message: z.string(), + timestamp: z.number(), + status: z.enum(['investigating', 'identified', 'monitoring', 'resolved']), + components: z.array( + z.object({ + id: z.string(), + type: z.enum(['website', 'monitor']), + status: z.enum([ + 'operational', + 'degradedPerformance', + 'partialOutage', + 'majorOutage', + 'underMaintenance', + ]), + }) + ), + }) + ), +}); diff --git a/src/server/prisma/zod/statuspageincident.ts b/src/server/prisma/zod/statuspageincident.ts new file mode 100644 index 0000000..4c19b0b --- /dev/null +++ b/src/server/prisma/zod/statuspageincident.ts @@ -0,0 +1,19 @@ +import * as z from "zod" +import * as imports from "./schemas/index.js" + +// Helper schema for JSON fields +type Literal = boolean | number | string +type Json = Literal | { [key: string]: Json } | Json[] +const literalSchema = z.union([z.string(), z.number(), z.boolean()]) +const jsonSchema: z.ZodSchema = z.lazy(() => z.union([literalSchema, z.array(jsonSchema), z.record(jsonSchema)])) + +export const StatusPageIncidentModelSchema = z.object({ + id: z.string(), + createdAt: z.date(), + updatedAt: z.date(), + name: z.string(), + /** + * [StatusPageIncidentPayload] + */ + payload: imports.StatusPageIncidentPayloadSchema, +}) diff --git a/src/server/types/global.d.ts b/src/server/types/global.d.ts index 8f45a21..5c325ce 100644 --- a/src/server/types/global.d.ts +++ b/src/server/types/global.d.ts @@ -2,6 +2,7 @@ import type { JWTPayload } from '../middleware/auth.ts'; import type { MonitorStatusPageListSchema, SurveyPayloadSchema, + StatusPageIncidentPayloadSchema, } from '../prisma/zod/schemas/index.ts'; declare global { @@ -17,5 +18,8 @@ declare global { } | null; type MonitorStatusPageList = z.infer; type SurveyPayload = z.infer; + type StatusPageIncidentPayload = z.infer< + typeof StatusPageIncidentPayloadSchema + >; } }