363 lines
12 KiB
Text
363 lines
12 KiB
Text
// This is your Prisma schema file,
|
|
// learn more about it in the docs: https://pris.ly/d/prisma-schema
|
|
|
|
generator client {
|
|
provider = "prisma-client-js"
|
|
}
|
|
|
|
datasource db {
|
|
provider = "postgresql"
|
|
}
|
|
|
|
// ============================================
|
|
// User Management & Authentication
|
|
// ============================================
|
|
|
|
model User {
|
|
id String @id @default(cuid())
|
|
entraOid String? @unique @map("entra_oid")
|
|
email String @unique
|
|
displayName String? @map("display_name")
|
|
department String?
|
|
isActive Boolean @default(true) @map("is_active")
|
|
lastLoginAt DateTime? @map("last_login_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
userRoles UserRole[]
|
|
createdTasks Task[] @relation("TaskCreatedBy")
|
|
completedTasks Task[] @relation("TaskCompletedBy")
|
|
taskAssignments TaskAssignment[]
|
|
createdTemplates TaskTemplate[]
|
|
syncLogs SyncLog[]
|
|
auditLogs AuditLog[]
|
|
notifications Notification[]
|
|
notificationPrefs NotificationPreference[]
|
|
|
|
@@map("users")
|
|
}
|
|
|
|
model Role {
|
|
id String @id @default(cuid())
|
|
name String @unique
|
|
description String?
|
|
permissions Json @default("{}")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
userRoles UserRole[]
|
|
entraGroupMappings EntraGroupRoleMapping[]
|
|
|
|
@@map("roles")
|
|
}
|
|
|
|
model UserRole {
|
|
id String @id @default(cuid())
|
|
userId String @map("user_id")
|
|
roleId String @map("role_id")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([userId, roleId])
|
|
@@map("user_roles")
|
|
}
|
|
|
|
model EntraGroupRoleMapping {
|
|
id String @id @default(cuid())
|
|
entraGroupId String @map("entra_group_id")
|
|
roleId String @map("role_id")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
role Role @relation(fields: [roleId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([entraGroupId, roleId])
|
|
@@map("entra_group_role_mappings")
|
|
}
|
|
|
|
// ============================================
|
|
// Client & Policy Management
|
|
// ============================================
|
|
|
|
model Designation {
|
|
id String @id @default(cuid())
|
|
name String @unique
|
|
description String?
|
|
color String
|
|
rules String?
|
|
displayOrder Int @map("display_order")
|
|
isActive Boolean @default(true) @map("is_active")
|
|
afwAnotId String? @unique @map("afw_anot_id")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
clientsDesignation1 Client[] @relation("ClientDesignation1")
|
|
clientsDesignation2 Client[] @relation("ClientDesignation2")
|
|
taskTemplates TaskTemplate[]
|
|
|
|
@@map("designations")
|
|
}
|
|
|
|
model Client {
|
|
id String @id @default(cuid())
|
|
amsCustomerId String @unique @map("ams_customer_id")
|
|
name String
|
|
addressLine1 String? @map("address_line1")
|
|
addressLine2 String? @map("address_line2")
|
|
city String?
|
|
state String?
|
|
zipCode String? @map("zip_code")
|
|
phone String?
|
|
email String?
|
|
producerCode String? @map("producer_code")
|
|
amsCreatedAt DateTime? @map("ams_created_at")
|
|
amsModifiedAt DateTime? @map("ams_modified_at")
|
|
designationId String? @map("designation_id")
|
|
designation2Id String? @map("designation2_id")
|
|
notes String? @db.Text
|
|
customFields Json @default("{}") @map("custom_fields")
|
|
lastSyncedAt DateTime? @map("last_synced_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
designation Designation? @relation("ClientDesignation1", fields: [designationId], references: [id])
|
|
designation2 Designation? @relation("ClientDesignation2", fields: [designation2Id], references: [id])
|
|
policies Policy[]
|
|
tasks Task[]
|
|
|
|
@@index([name])
|
|
@@index([designationId])
|
|
@@index([designation2Id])
|
|
@@map("clients")
|
|
}
|
|
|
|
model Policy {
|
|
id String @id @default(cuid())
|
|
amsPolicyId String @unique @map("ams_policy_id")
|
|
clientId String @map("client_id")
|
|
policyNumber String? @map("policy_number")
|
|
policyType String? @map("policy_type")
|
|
effectiveDate DateTime? @map("effective_date")
|
|
expirationDate DateTime @map("expiration_date")
|
|
carrierName String? @map("carrier_name")
|
|
writingCompanyName String? @map("writing_company_name")
|
|
premiumAmount Decimal? @map("premium_amount") @db.Decimal(12, 2)
|
|
status String?
|
|
billMethod String? @map("bill_method")
|
|
businessType String? @map("business_type")
|
|
department String?
|
|
executiveName String? @map("executive_name")
|
|
csrName String? @map("csr_name")
|
|
additionalRep1 String? @map("additional_rep1")
|
|
additionalRep2 String? @map("additional_rep2")
|
|
additionalExec1 String? @map("additional_exec1")
|
|
additionalExec2 String? @map("additional_exec2")
|
|
amsCreatedAt DateTime? @map("ams_created_at")
|
|
amsModifiedAt DateTime? @map("ams_modified_at")
|
|
lastSyncedAt DateTime? @map("last_synced_at")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
client Client @relation(fields: [clientId], references: [id], onDelete: Cascade)
|
|
tasks Task[]
|
|
|
|
@@index([clientId])
|
|
@@index([expirationDate])
|
|
@@index([department])
|
|
@@map("policies")
|
|
}
|
|
|
|
// ============================================
|
|
// Task Management
|
|
// ============================================
|
|
|
|
enum TaskStatus {
|
|
NOT_STARTED
|
|
IN_PROGRESS
|
|
COMPLETED
|
|
BLOCKED
|
|
NA
|
|
CANCELLED
|
|
}
|
|
|
|
enum TaskPriority {
|
|
LOW
|
|
MEDIUM
|
|
HIGH
|
|
URGENT
|
|
}
|
|
|
|
enum TaskTiming {
|
|
PRE_RENEWAL
|
|
POST_RENEWAL
|
|
}
|
|
|
|
enum DepartmentType {
|
|
PERSONAL_LINES
|
|
COMMERCIAL_LINES
|
|
CLAIMS
|
|
BENEFITS
|
|
OTHER
|
|
}
|
|
|
|
model TaskTemplate {
|
|
id String @id @default(cuid())
|
|
name String
|
|
description String? @db.Text
|
|
department DepartmentType
|
|
timing TaskTiming
|
|
daysOffset Int @map("days_offset")
|
|
defaultPriority TaskPriority @map("default_priority")
|
|
isActive Boolean @default(true) @map("is_active")
|
|
displayOrder Int? @map("display_order")
|
|
designationId String? @map("designation_id")
|
|
createdBy String? @map("created_by")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
designation Designation? @relation(fields: [designationId], references: [id])
|
|
creator User? @relation(fields: [createdBy], references: [id])
|
|
tasks Task[]
|
|
|
|
@@index([designationId])
|
|
@@map("task_templates")
|
|
}
|
|
|
|
model Task {
|
|
id String @id @default(cuid())
|
|
title String
|
|
description String? @db.Text
|
|
department DepartmentType
|
|
timing TaskTiming
|
|
daysOffset Int @map("days_offset")
|
|
dueDate DateTime @map("due_date")
|
|
status TaskStatus @default(NOT_STARTED)
|
|
priority TaskPriority
|
|
clientId String @map("client_id")
|
|
policyId String? @map("policy_id")
|
|
templateId String? @map("template_id")
|
|
createdBy String? @map("created_by")
|
|
completedAt DateTime? @map("completed_at")
|
|
completedBy String? @map("completed_by")
|
|
naReason String? @map("na_reason") @db.Text
|
|
cancelledReason String? @map("cancelled_reason") @db.Text
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
client Client @relation(fields: [clientId], references: [id], onDelete: Cascade)
|
|
policy Policy? @relation(fields: [policyId], references: [id])
|
|
template TaskTemplate? @relation(fields: [templateId], references: [id])
|
|
creator User? @relation("TaskCreatedBy", fields: [createdBy], references: [id])
|
|
completer User? @relation("TaskCompletedBy", fields: [completedBy], references: [id])
|
|
assignments TaskAssignment[]
|
|
|
|
@@index([clientId])
|
|
@@index([policyId])
|
|
@@index([status])
|
|
@@index([dueDate])
|
|
@@index([department])
|
|
@@map("tasks")
|
|
}
|
|
|
|
model TaskAssignment {
|
|
id String @id @default(cuid())
|
|
taskId String @map("task_id")
|
|
userId String @map("user_id")
|
|
assignedAt DateTime @default(now()) @map("assigned_at")
|
|
|
|
task Task @relation(fields: [taskId], references: [id], onDelete: Cascade)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([taskId, userId])
|
|
@@map("task_assignments")
|
|
}
|
|
|
|
// ============================================
|
|
// Sync & System Management
|
|
// ============================================
|
|
|
|
model SyncLog {
|
|
id String @id @default(cuid())
|
|
syncType String @map("sync_type")
|
|
startedAt DateTime @default(now()) @map("started_at")
|
|
completedAt DateTime? @map("completed_at")
|
|
status String
|
|
rowsProcessed Int @default(0) @map("rows_processed")
|
|
rowsInserted Int @default(0) @map("rows_inserted")
|
|
rowsUpdated Int @default(0) @map("rows_updated")
|
|
errorMessage String? @map("error_message") @db.Text
|
|
triggeredBy String? @map("triggered_by")
|
|
|
|
user User? @relation(fields: [triggeredBy], references: [id])
|
|
|
|
@@index([syncType])
|
|
@@index([startedAt])
|
|
@@map("sync_logs")
|
|
}
|
|
|
|
model SyncConfig {
|
|
id String @id @default(cuid())
|
|
key String @unique
|
|
value String @db.Text
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
@@map("sync_config")
|
|
}
|
|
|
|
model AuditLog {
|
|
id String @id @default(cuid())
|
|
userId String? @map("user_id")
|
|
action String
|
|
entityType String @map("entity_type")
|
|
entityId String? @map("entity_id")
|
|
oldValues Json? @map("old_values")
|
|
newValues Json? @map("new_values")
|
|
ipAddress String? @map("ip_address")
|
|
userAgent String? @map("user_agent") @db.Text
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
user User? @relation(fields: [userId], references: [id])
|
|
|
|
@@index([userId])
|
|
@@index([entityType])
|
|
@@index([createdAt])
|
|
@@map("audit_logs")
|
|
}
|
|
|
|
// ============================================
|
|
// Notifications
|
|
// ============================================
|
|
|
|
model Notification {
|
|
id String @id @default(cuid())
|
|
userId String @map("user_id")
|
|
type String
|
|
title String
|
|
message String @db.Text
|
|
relatedEntityType String? @map("related_entity_type")
|
|
relatedEntityId String? @map("related_entity_id")
|
|
isRead Boolean @default(false) @map("is_read")
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId, isRead])
|
|
@@index([createdAt])
|
|
@@map("notifications")
|
|
}
|
|
|
|
model NotificationPreference {
|
|
id String @id @default(cuid())
|
|
userId String @map("user_id")
|
|
notificationType String @map("notification_type")
|
|
inApp Boolean @default(true) @map("in_app")
|
|
email Boolean @default(false)
|
|
teams Boolean @default(false)
|
|
createdAt DateTime @default(now()) @map("created_at")
|
|
updatedAt DateTime @updatedAt @map("updated_at")
|
|
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([userId, notificationType])
|
|
@@map("notification_preferences")
|
|
}
|