generator client { provider = "prisma-client-js" } datasource db { provider = "postgresql" url = env("DATABASE_URL") } enum MailProvider { GMAIL GMX WEBDE } enum UserRole { USER ADMIN } enum JobStatus { QUEUED RUNNING SUCCEEDED FAILED CANCELED } enum RuleActionType { MOVE DELETE ARCHIVE LABEL } enum RuleConditionType { HEADER SUBJECT FROM LIST_UNSUBSCRIBE LIST_ID } model Tenant { id String @id @default(cuid()) name String isActive Boolean @default(true) exportJobs ExportJob[] createdAt DateTime @default(now()) updatedAt DateTime @updatedAt users User[] mailboxAccounts MailboxAccount[] rules Rule[] jobs CleanupJob[] } enum ExportStatus { QUEUED RUNNING DONE FAILED } model ExportJob { id String @id @default(cuid()) tenantId String status ExportStatus @default(QUEUED) format String scope String filePath String? error String? expiresAt DateTime? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt tenant Tenant @relation(fields: [tenantId], references: [id]) @@index([tenantId]) } model User { id String @id @default(cuid()) tenantId String email String @unique password String role UserRole @default(USER) isActive Boolean @default(true) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt tenant Tenant @relation(fields: [tenantId], references: [id]) } model MailboxAccount { id String @id @default(cuid()) tenantId String email String provider MailProvider isActive Boolean @default(true) imapHost String imapPort Int imapTLS Boolean smtpHost String? smtpPort Int? smtpTLS Boolean? oauthToken String? oauthRefreshToken String? oauthAccessToken String? oauthExpiresAt DateTime? providerUserId String? appPassword String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt tenant Tenant @relation(fields: [tenantId], references: [id]) folders MailboxFolder[] jobs CleanupJob[] @@index([tenantId]) } model MailboxFolder { id String @id @default(cuid()) mailboxAccountId String name String remoteId String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt mailboxAccount MailboxAccount @relation(fields: [mailboxAccountId], references: [id]) mailItems MailItem[] @@index([mailboxAccountId]) } model MailItem { id String @id @default(cuid()) folderId String messageId String subject String? from String? receivedAt DateTime? listId String? listUnsubscribe String? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt folder MailboxFolder @relation(fields: [folderId], references: [id]) @@index([folderId]) @@index([messageId]) } model Rule { id String @id @default(cuid()) tenantId String name String enabled Boolean @default(true) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt tenant Tenant @relation(fields: [tenantId], references: [id]) conditions RuleCondition[] actions RuleAction[] @@index([tenantId]) } model RuleCondition { id String @id @default(cuid()) ruleId String type RuleConditionType value String rule Rule @relation(fields: [ruleId], references: [id]) @@index([ruleId]) } model RuleAction { id String @id @default(cuid()) ruleId String type RuleActionType target String? rule Rule @relation(fields: [ruleId], references: [id]) @@index([ruleId]) } model CleanupJob { id String @id @default(cuid()) tenantId String mailboxAccountId String status JobStatus @default(QUEUED) dryRun Boolean @default(true) unsubscribeEnabled Boolean @default(true) routingEnabled Boolean @default(true) startedAt DateTime? finishedAt DateTime? createdAt DateTime @default(now()) updatedAt DateTime @updatedAt tenant Tenant @relation(fields: [tenantId], references: [id]) mailboxAccount MailboxAccount @relation(fields: [mailboxAccountId], references: [id]) unsubscribeAttempts UnsubscribeAttempt[] events CleanupJobEvent[] @@index([tenantId]) @@index([mailboxAccountId]) } model UnsubscribeAttempt { id String @id @default(cuid()) jobId String mailItemId String? method String target String status String createdAt DateTime @default(now()) job CleanupJob @relation(fields: [jobId], references: [id]) @@index([jobId]) } model CleanupJobEvent { id String @id @default(cuid()) jobId String level String message String progress Int? createdAt DateTime @default(now()) job CleanupJob @relation(fields: [jobId], references: [id]) @@index([jobId]) }