Alert system
This commit is contained in:
@@ -25,12 +25,16 @@ model Org {
|
||||
machineSettings MachineSettings[]
|
||||
settingsAudits SettingsAudit[]
|
||||
invites OrgInvite[]
|
||||
alertPolicies AlertPolicy[]
|
||||
alertContacts AlertContact[]
|
||||
alertNotifications AlertNotification[]
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(uuid())
|
||||
email String @unique
|
||||
name String?
|
||||
phone String? @map("phone")
|
||||
passwordHash String
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
@@ -41,6 +45,8 @@ model User {
|
||||
orgs OrgUser[]
|
||||
sessions Session[]
|
||||
sentInvites OrgInvite[] @relation("OrgInviteInviter")
|
||||
alertContacts AlertContact[]
|
||||
alertNotifications AlertNotification[]
|
||||
}
|
||||
|
||||
model OrgUser {
|
||||
@@ -123,6 +129,7 @@ model Machine {
|
||||
workOrders MachineWorkOrder[]
|
||||
settings MachineSettings?
|
||||
settingsAudits SettingsAudit[]
|
||||
alertNotifications AlertNotification[]
|
||||
|
||||
@@unique([orgId, name])
|
||||
@@index([orgId])
|
||||
@@ -306,6 +313,70 @@ model OrgSettings {
|
||||
@@map("org_settings")
|
||||
}
|
||||
|
||||
model AlertPolicy {
|
||||
id String @id @default(uuid())
|
||||
orgId String @map("org_id")
|
||||
policyJson Json @map("policy_json")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
updatedBy String? @map("updated_by")
|
||||
|
||||
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@unique([orgId])
|
||||
@@index([orgId])
|
||||
@@map("alert_policies")
|
||||
}
|
||||
|
||||
model AlertContact {
|
||||
id String @id @default(uuid())
|
||||
orgId String @map("org_id")
|
||||
userId String? @map("user_id")
|
||||
name String
|
||||
roleScope String @map("role_scope") // MEMBER | ADMIN | OWNER | CUSTOM
|
||||
email String?
|
||||
phone String?
|
||||
eventTypes Json? @map("event_types") // optional allowlist (array of strings)
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
||||
notifications AlertNotification[]
|
||||
|
||||
@@unique([orgId, userId])
|
||||
@@index([orgId])
|
||||
@@index([orgId, roleScope])
|
||||
@@map("alert_contacts")
|
||||
}
|
||||
|
||||
model AlertNotification {
|
||||
id String @id @default(uuid())
|
||||
orgId String @map("org_id")
|
||||
machineId String @map("machine_id")
|
||||
eventId String @map("event_id")
|
||||
eventType String @map("event_type")
|
||||
ruleId String @map("rule_id")
|
||||
role String
|
||||
channel String
|
||||
contactId String? @map("contact_id")
|
||||
userId String? @map("user_id")
|
||||
sentAt DateTime @default(now()) @map("sent_at")
|
||||
status String
|
||||
error String?
|
||||
|
||||
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
|
||||
machine Machine @relation(fields: [machineId], references: [id], onDelete: Cascade)
|
||||
contact AlertContact? @relation(fields: [contactId], references: [id], onDelete: SetNull)
|
||||
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([orgId, machineId, sentAt])
|
||||
@@index([orgId, eventId, role, channel])
|
||||
@@index([userId])
|
||||
@@index([contactId])
|
||||
@@map("alert_notifications")
|
||||
}
|
||||
|
||||
model OrgShift {
|
||||
id String @id @default(uuid())
|
||||
orgId String @map("org_id")
|
||||
|
||||
Reference in New Issue
Block a user