feat: add workspace audit log db model
This commit is contained in:
parent
0502185e7c
commit
7243b991ae
20
src/server/model/auditLog.ts
Normal file
20
src/server/model/auditLog.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { WorkspaceAuditLogType } from '@prisma/client';
|
||||||
|
import { prisma } from './_client';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* create audit log which can query by log
|
||||||
|
*/
|
||||||
|
export async function createAuditLog(info: {
|
||||||
|
workspaceId: string;
|
||||||
|
relatedId?: string;
|
||||||
|
relatedType?: WorkspaceAuditLogType;
|
||||||
|
content: string;
|
||||||
|
}) {
|
||||||
|
const log = await prisma.workspaceAuditLog.create({
|
||||||
|
data: {
|
||||||
|
...info,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return log;
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
-- CreateEnum
|
||||||
|
CREATE TYPE "WorkspaceAuditLogType" AS ENUM ('Monitor', 'Notification');
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Workspace" ADD COLUMN "settings" JSONB NOT NULL DEFAULT '{}';
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "WorkspaceAuditLog" (
|
||||||
|
"id" VARCHAR(30) NOT NULL,
|
||||||
|
"workspaceId" VARCHAR(30) NOT NULL,
|
||||||
|
"content" TEXT NOT NULL,
|
||||||
|
"relatedId" TEXT,
|
||||||
|
"relatedType" "WorkspaceAuditLogType",
|
||||||
|
"createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
||||||
|
CONSTRAINT "WorkspaceAuditLog_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE INDEX "WorkspaceAuditLog_createdAt_idx" ON "WorkspaceAuditLog"("createdAt");
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "WorkspaceAuditLog" ADD CONSTRAINT "WorkspaceAuditLog_workspaceId_fkey" FOREIGN KEY ("workspaceId") REFERENCES "Workspace"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
@ -52,6 +52,7 @@ model Workspace {
|
|||||||
// for user currentWorkspace
|
// for user currentWorkspace
|
||||||
selectedUsers User[] // user list who select this workspace, not use in most of case
|
selectedUsers User[] // user list who select this workspace, not use in most of case
|
||||||
workspaceDailyUsage WorkspaceDailyUsage[]
|
workspaceDailyUsage WorkspaceDailyUsage[]
|
||||||
|
workspaceAuditLog WorkspaceAuditLog[]
|
||||||
}
|
}
|
||||||
|
|
||||||
model WorkspacesOnUsers {
|
model WorkspacesOnUsers {
|
||||||
@ -342,3 +343,21 @@ model WorkspaceDailyUsage {
|
|||||||
|
|
||||||
@@unique([workspaceId, date])
|
@@unique([workspaceId, date])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model WorkspaceAuditLog {
|
||||||
|
id String @id @default(cuid()) @db.VarChar(30)
|
||||||
|
workspaceId String @db.VarChar(30)
|
||||||
|
content String
|
||||||
|
relatedId String?
|
||||||
|
relatedType WorkspaceAuditLogType?
|
||||||
|
createdAt DateTime @default(now()) @db.Timestamptz(6)
|
||||||
|
|
||||||
|
workspace Workspace @relation(fields: [workspaceId], references: [id], onUpdate: Cascade, onDelete: Cascade)
|
||||||
|
|
||||||
|
@@index([createdAt])
|
||||||
|
}
|
||||||
|
|
||||||
|
enum WorkspaceAuditLogType {
|
||||||
|
Monitor
|
||||||
|
Notification
|
||||||
|
}
|
||||||
|
@ -15,3 +15,4 @@ export * from "./monitordata"
|
|||||||
export * from "./monitorstatus"
|
export * from "./monitorstatus"
|
||||||
export * from "./monitorstatuspage"
|
export * from "./monitorstatuspage"
|
||||||
export * from "./workspacedailyusage"
|
export * from "./workspacedailyusage"
|
||||||
|
export * from "./workspaceauditlog"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as z from "zod"
|
import * as z from "zod"
|
||||||
import * as imports from "./schemas"
|
import * as imports from "./schemas"
|
||||||
import { CompleteWorkspacesOnUsers, RelatedWorkspacesOnUsersModelSchema, CompleteWebsite, RelatedWebsiteModelSchema, CompleteNotification, RelatedNotificationModelSchema, CompleteMonitor, RelatedMonitorModelSchema, CompleteMonitorStatusPage, RelatedMonitorStatusPageModelSchema, CompleteUser, RelatedUserModelSchema, CompleteWorkspaceDailyUsage, RelatedWorkspaceDailyUsageModelSchema } from "./index"
|
import { CompleteWorkspacesOnUsers, RelatedWorkspacesOnUsersModelSchema, CompleteWebsite, RelatedWebsiteModelSchema, CompleteNotification, RelatedNotificationModelSchema, CompleteMonitor, RelatedMonitorModelSchema, CompleteMonitorStatusPage, RelatedMonitorStatusPageModelSchema, CompleteUser, RelatedUserModelSchema, CompleteWorkspaceDailyUsage, RelatedWorkspaceDailyUsageModelSchema, CompleteWorkspaceAuditLog, RelatedWorkspaceAuditLogModelSchema } from "./index"
|
||||||
|
|
||||||
// Helper schema for JSON fields
|
// Helper schema for JSON fields
|
||||||
type Literal = boolean | number | string
|
type Literal = boolean | number | string
|
||||||
@ -32,6 +32,7 @@ export interface CompleteWorkspace extends z.infer<typeof WorkspaceModelSchema>
|
|||||||
monitorStatusPages: CompleteMonitorStatusPage[]
|
monitorStatusPages: CompleteMonitorStatusPage[]
|
||||||
selectedUsers: CompleteUser[]
|
selectedUsers: CompleteUser[]
|
||||||
workspaceDailyUsage: CompleteWorkspaceDailyUsage[]
|
workspaceDailyUsage: CompleteWorkspaceDailyUsage[]
|
||||||
|
workspaceAuditLog: CompleteWorkspaceAuditLog[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,4 +48,5 @@ export const RelatedWorkspaceModelSchema: z.ZodSchema<CompleteWorkspace> = z.laz
|
|||||||
monitorStatusPages: RelatedMonitorStatusPageModelSchema.array(),
|
monitorStatusPages: RelatedMonitorStatusPageModelSchema.array(),
|
||||||
selectedUsers: RelatedUserModelSchema.array(),
|
selectedUsers: RelatedUserModelSchema.array(),
|
||||||
workspaceDailyUsage: RelatedWorkspaceDailyUsageModelSchema.array(),
|
workspaceDailyUsage: RelatedWorkspaceDailyUsageModelSchema.array(),
|
||||||
|
workspaceAuditLog: RelatedWorkspaceAuditLogModelSchema.array(),
|
||||||
}))
|
}))
|
||||||
|
26
src/server/prisma/zod/workspaceauditlog.ts
Normal file
26
src/server/prisma/zod/workspaceauditlog.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import * as z from "zod"
|
||||||
|
import * as imports from "./schemas"
|
||||||
|
import { WorkspaceAuditLogType } from "@prisma/client"
|
||||||
|
import { CompleteWorkspace, RelatedWorkspaceModelSchema } from "./index"
|
||||||
|
|
||||||
|
export const WorkspaceAuditLogModelSchema = z.object({
|
||||||
|
id: z.string(),
|
||||||
|
workspaceId: z.string(),
|
||||||
|
content: z.string(),
|
||||||
|
relatedId: z.string().nullish(),
|
||||||
|
relatedType: z.nativeEnum(WorkspaceAuditLogType).nullish(),
|
||||||
|
createdAt: z.date(),
|
||||||
|
})
|
||||||
|
|
||||||
|
export interface CompleteWorkspaceAuditLog extends z.infer<typeof WorkspaceAuditLogModelSchema> {
|
||||||
|
workspace: CompleteWorkspace
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RelatedWorkspaceAuditLogModelSchema contains all relations on your model in addition to the scalars
|
||||||
|
*
|
||||||
|
* NOTE: Lazy required in case of potential circular dependencies within schema
|
||||||
|
*/
|
||||||
|
export const RelatedWorkspaceAuditLogModelSchema: z.ZodSchema<CompleteWorkspaceAuditLog> = z.lazy(() => WorkspaceAuditLogModelSchema.extend({
|
||||||
|
workspace: RelatedWorkspaceModelSchema,
|
||||||
|
}))
|
Loading…
Reference in New Issue
Block a user