auditing
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "AuditEvent" (
|
||||
"id" TEXT NOT NULL PRIMARY KEY,
|
||||
"actorId" TEXT,
|
||||
"entityType" TEXT NOT NULL,
|
||||
"entityId" TEXT,
|
||||
"action" TEXT NOT NULL,
|
||||
"summary" TEXT NOT NULL,
|
||||
"metadataJson" TEXT NOT NULL,
|
||||
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "AuditEvent_actorId_fkey" FOREIGN KEY ("actorId") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "AuditEvent_createdAt_idx" ON "AuditEvent"("createdAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "AuditEvent_entityType_entityId_createdAt_idx" ON "AuditEvent"("entityType", "entityId", "createdAt");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "AuditEvent_actorId_createdAt_idx" ON "AuditEvent"("actorId", "createdAt");
|
||||
@@ -29,6 +29,7 @@ model User {
|
||||
salesQuoteRevisionsCreated SalesQuoteRevision[] @relation("SalesQuoteRevisionCreatedBy")
|
||||
salesOrderRevisionsCreated SalesOrderRevision[] @relation("SalesOrderRevisionCreatedBy")
|
||||
inventoryTransfersCreated InventoryTransfer[] @relation("InventoryTransferCreatedBy")
|
||||
auditEvents AuditEvent[]
|
||||
}
|
||||
|
||||
model Role {
|
||||
@@ -698,3 +699,19 @@ model PurchaseReceiptLine {
|
||||
@@index([purchaseReceiptId])
|
||||
@@index([purchaseOrderLineId])
|
||||
}
|
||||
|
||||
model AuditEvent {
|
||||
id String @id @default(cuid())
|
||||
actorId String?
|
||||
entityType String
|
||||
entityId String?
|
||||
action String
|
||||
summary String
|
||||
metadataJson String
|
||||
createdAt DateTime @default(now())
|
||||
actor User? @relation(fields: [actorId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([createdAt])
|
||||
@@index([entityType, entityId, createdAt])
|
||||
@@index([actorId, createdAt])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user