317 lines
13 KiB
Plaintext
317 lines
13 KiB
Plaintext
model User {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
/// Stored normalized for new writes. A functional lower(trim(email))
|
|
/// unique index in migration SQL also protects legacy mixed-case rows.
|
|
email String @unique
|
|
passwordHash String?
|
|
firstName String
|
|
lastName String
|
|
avatar String?
|
|
phone String?
|
|
defaultTenantId String?
|
|
verifyToken String?
|
|
verifyTokenCreatedAt DateTime?
|
|
locale String?
|
|
lightOrDarkMode String?
|
|
totpSecretEncrypted String?
|
|
totpPendingSecretEncrypted String?
|
|
totpEnabledAt DateTime?
|
|
totpPendingCreatedAt DateTime?
|
|
mfaRecoveryCodeHashes Json?
|
|
mfaRecoveryCodesGeneratedAt DateTime?
|
|
mfaRecoveryCodeLastUsedAt DateTime?
|
|
active Boolean @default(false)
|
|
// Phase 10 Task #68 — DSGVO bulk-ops self-service flags.
|
|
// `pendingDeletion` is set the moment the user confirms a delete request via
|
|
// the email-verification token; `scheduledDeletionAt` carries the 30-day
|
|
// grace deadline. `pseudonymized` is flipped permanently once the cascade
|
|
// job has rewritten PII to deterministic pseudonyms (Art. 17 alternative
|
|
// path for retention-bound rows such as AuditEvents). `deletionRequestId`
|
|
// is the idempotency token shared with the worker job + audit trail.
|
|
pendingDeletion Boolean @default(false)
|
|
scheduledDeletionAt DateTime?
|
|
deletionRequestedAt DateTime?
|
|
pseudonymized Boolean @default(false)
|
|
pseudonymizedAt DateTime?
|
|
deletionRequestId String? @unique
|
|
createdApiKeys ApiKey[]
|
|
createdGroups Group[]
|
|
groups GroupUser[]
|
|
logs Log[]
|
|
tenants TenantUser[]
|
|
invitation TenantUserInvitation? @relation("createdUser")
|
|
sentInvitations TenantUserInvitation[] @relation("fromUser")
|
|
acceptedInvitations TenantUserInvitation[] @relation("acceptedByUser")
|
|
revokedInvitations TenantUserInvitation[] @relation("revokedByUser")
|
|
roles UserRole[]
|
|
readEmails EmailRead[]
|
|
onboardingSessions OnboardingSession[]
|
|
tenantIpAddresses TenantIpAddress[]
|
|
analyticsUniqueSessions AnalyticsUniqueVisitor[]
|
|
metricLogs MetricLog[]
|
|
knowledgeBaseArticles KnowledgeBaseArticle[]
|
|
events Event[]
|
|
workflowsCreated Workflow[] @relation("createdByUser")
|
|
workflowsExecuted WorkflowExecution[] @relation("executedByUser")
|
|
workflowVariablesCreated WorkflowVariable[]
|
|
workflowCredentialsCreated WorkflowCredential[]
|
|
feedback Feedback[]
|
|
supportTickets SupportTicket[]
|
|
assignedSupportTickets SupportTicket[] @relation("supportTicketAssignee")
|
|
credits Credit[]
|
|
portals Portal[]
|
|
impersonationAuditsActor ImpersonationAudit[] @relation("ImpersonationAuditActor")
|
|
impersonationAuditsTarget ImpersonationAudit[] @relation("ImpersonationAuditTarget")
|
|
notificationDeliveries NotificationDelivery[]
|
|
userSessions UserSession[]
|
|
trustedDevices TrustedDevice[]
|
|
notificationPreferences UserNotificationPreference[]
|
|
deviceTokens DeviceToken[]
|
|
magicLinkTokens MagicLinkToken[]
|
|
|
|
// Apps-Engine (R-P5) uses bare String scalars for tenantId/createdByUserId
|
|
// (AD-21) — no back-relations here.
|
|
|
|
sitesCreated Site[] @relation("sitesCreatedByUser")
|
|
|
|
// Phase 10 Task #68 — grace-period cron query scans pendingDeletion users
|
|
// whose deadline has elapsed. Index keeps the cron O(log n).
|
|
@@index([pendingDeletion, scheduledDeletionAt], name: "user_pending_deletion_due_idx")
|
|
}
|
|
|
|
model MagicLinkToken {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
userId String
|
|
tokenHash String @unique
|
|
expiresAt DateTime
|
|
consumedAt DateTime?
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([userId, expiresAt])
|
|
@@index([expiresAt, consumedAt])
|
|
}
|
|
|
|
model Tenant {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
slug String @unique
|
|
name String
|
|
icon String?
|
|
logo String?
|
|
subscriptionId String?
|
|
active Boolean @default(false)
|
|
deactivatedReason String?
|
|
apiKeys ApiKey[]
|
|
apiKeyLogs ApiKeyLog[]
|
|
idempotencyKeys IdempotencyKey[]
|
|
groups Group[]
|
|
logs Log[]
|
|
subscription TenantSubscription?
|
|
productConfiguration TenantProductConfiguration?
|
|
featureOverrides TenantFeatureOverride[]
|
|
users TenantUser[]
|
|
roles Role[]
|
|
invitations TenantUserInvitation[]
|
|
userRoles UserRole[]
|
|
inboundAddresses TenantInboundAddress[]
|
|
events Event[]
|
|
fromRegistration Registration?
|
|
emailSenders EmailSender[]
|
|
campaigns Campaign[]
|
|
outboundEmails OutboundEmail[]
|
|
onboardingSessions OnboardingSession[]
|
|
onboardingDemoProvisionings OnboardingDemoProvisioning[]
|
|
ipAddresses TenantIpAddress[]
|
|
metricLogs MetricLog[]
|
|
knowledgeBases KnowledgeBase[]
|
|
workflows Workflow[]
|
|
workflowExecutions WorkflowExecution[]
|
|
workflowVariables WorkflowVariable[]
|
|
workflowCredentials WorkflowCredential[]
|
|
feedback Feedback[]
|
|
supportTickets SupportTicket[]
|
|
credits Credit[]
|
|
checkoutSessions CheckoutSessionStatus[]
|
|
productAcquisitions TenantProductAcquisition[]
|
|
portals Portal[]
|
|
portalsUsers PortalUser[]
|
|
widgets Widget[]
|
|
impersonationAudits ImpersonationAudit[]
|
|
adminTenantNotes AdminTenantNote[]
|
|
notificationDeliveries NotificationDelivery[]
|
|
notificationPreferences UserNotificationPreference[]
|
|
deviceTokens DeviceToken[]
|
|
authProviders WorkspaceAuthProvider[]
|
|
|
|
theme String?
|
|
themeConfig String?
|
|
|
|
// Apps-Engine (R-P5): App is global; DataConnection/AppSyncRun use bare
|
|
// tenantId scalars (AD-21) — no back-relations here.
|
|
|
|
// Global du/Sie formality toggle (Anrede). Default "du" keeps the effective
|
|
// i18next language equal to the base locale, so existing rendering stays
|
|
// byte-identical; "sie" resolves to the "<locale>-formal" variant.
|
|
anrede String? @default("du")
|
|
|
|
sites Site[]
|
|
|
|
forms Form[]
|
|
|
|
@@index([slug])
|
|
}
|
|
|
|
model WorkspaceAuthProvider {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
updatedAt DateTime @updatedAt
|
|
tenantId String
|
|
kind String
|
|
name String
|
|
slug String
|
|
enabled Boolean @default(false)
|
|
issuer String?
|
|
authorizationUrl String?
|
|
tokenUrl String?
|
|
jwksUrl String?
|
|
clientId String?
|
|
entityId String?
|
|
ssoUrl String?
|
|
certificateFingerprint String?
|
|
metadataUpdatedAt DateTime?
|
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([tenantId, slug])
|
|
@@index([tenantId, kind, enabled])
|
|
@@index([tenantId, updatedAt])
|
|
}
|
|
|
|
model ImpersonationAudit {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
actorUserId String?
|
|
targetUserId String?
|
|
tenantId String?
|
|
action String
|
|
reason String?
|
|
requestPath String
|
|
metadata String?
|
|
actor User? @relation("ImpersonationAuditActor", fields: [actorUserId], references: [id], onDelete: SetNull)
|
|
target User? @relation("ImpersonationAuditTarget", fields: [targetUserId], references: [id], onDelete: SetNull)
|
|
tenant Tenant? @relation(fields: [tenantId], references: [id], onDelete: SetNull)
|
|
|
|
@@index([actorUserId])
|
|
@@index([targetUserId])
|
|
@@index([tenantId])
|
|
@@index([createdAt])
|
|
}
|
|
|
|
// Seat billing bucket / default UI mode. `office` = back-office / desk work,
|
|
// `field` = on-site (Baustelle) work. Shared across the Prisma schema folder
|
|
// (Role.seatCategory, TenantUser.seatType).
|
|
enum SeatType {
|
|
office
|
|
field
|
|
}
|
|
|
|
model TenantUser {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
tenantId String
|
|
userId String
|
|
type Int
|
|
joined Int
|
|
status Int
|
|
// null = derived from the user's roles at read time (any office role => office
|
|
// seat); an explicit value is an admin billing override.
|
|
seatType SeatType?
|
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
|
|
@@unique([tenantId, userId])
|
|
@@index([userId])
|
|
@@index([tenantId, status])
|
|
}
|
|
|
|
model TenantUserInvitation {
|
|
id String @id @default(cuid())
|
|
tenantId String
|
|
email String
|
|
firstName String
|
|
lastName String
|
|
type Int
|
|
pending Boolean
|
|
status String @default("pending")
|
|
tokenHash String?
|
|
tokenPrefix String?
|
|
expiresAt DateTime?
|
|
acceptedAt DateTime?
|
|
revokedAt DateTime?
|
|
createdUserId String? @unique
|
|
fromUserId String?
|
|
acceptedByUserId String?
|
|
revokedByUserId String?
|
|
fromUser User? @relation(name: "fromUser", fields: [fromUserId], references: [id])
|
|
user User? @relation(name: "createdUser", fields: [createdUserId], references: [id])
|
|
acceptedByUser User? @relation(name: "acceptedByUser", fields: [acceptedByUserId], references: [id])
|
|
revokedByUser User? @relation(name: "revokedByUser", fields: [revokedByUserId], references: [id])
|
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
|
|
/// One live pending invite per tenant and normalized email is enforced by a
|
|
/// partial functional index in migration SQL. A second partial unique index
|
|
/// protects every non-null token hash globally. Prisma cannot declare either.
|
|
@@index([tenantId, status, expiresAt])
|
|
@@index([tenantId, email, status])
|
|
@@index([tenantId, tokenPrefix])
|
|
@@index([acceptedByUserId])
|
|
@@index([revokedByUserId])
|
|
}
|
|
|
|
model Registration {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
email String @unique
|
|
firstName String
|
|
lastName String
|
|
slug String?
|
|
token String @unique
|
|
ipAddress String?
|
|
company String?
|
|
selectedSubscriptionPriceId String?
|
|
selectedOfficeSeatQuantity Int?
|
|
selectedFieldSeatQuantity Int?
|
|
leadConversionLeadId String?
|
|
leadConversionToken String?
|
|
leadConversionPlanId String?
|
|
createdTenantId String? @unique
|
|
createdTenant Tenant? @relation(fields: [createdTenantId], references: [id], onDelete: Cascade)
|
|
}
|
|
|
|
model Blacklist {
|
|
id String @id @default(cuid())
|
|
createdAt DateTime @default(now())
|
|
type String // email, domain, ip
|
|
value String
|
|
active Boolean @default(true)
|
|
registerAttempts Int @default(0)
|
|
}
|
|
|
|
model TenantIpAddress {
|
|
id String @id @default(cuid())
|
|
tenantId String
|
|
tenant Tenant @relation(fields: [tenantId], references: [id], onDelete: Cascade)
|
|
userId String?
|
|
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
apiKeyId String?
|
|
apiKey ApiKey? @relation(fields: [apiKeyId], references: [id], onDelete: Cascade)
|
|
ip String
|
|
fromUrl String
|
|
createdAt DateTime @default(now())
|
|
|
|
@@unique([tenantId, ip, userId, apiKeyId])
|
|
}
|