@danielcok17/prisma-db 1.8.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/prisma/app.prisma +20 -0
- package/prisma/law.prisma +45 -47
- package/prisma/migrations/20260120212010_add_user_company_fields/migration.sql +22 -0
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -24
- package/dist/index.js.map +0 -1
- package/dist/paths.d.ts +0 -4
- package/dist/paths.d.ts.map +0 -1
- package/dist/paths.js +0 -12
- package/dist/paths.js.map +0 -1
- package/dist/utils.d.ts +0 -5
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -13
- package/dist/utils.js.map +0 -1
- package/prisma/generated/app/client.d.ts +0 -1
- package/prisma/generated/app/client.js +0 -4
- package/prisma/generated/app/default.d.ts +0 -1
- package/prisma/generated/app/default.js +0 -4
- package/prisma/generated/app/edge.d.ts +0 -1
- package/prisma/generated/app/edge.js +0 -754
- package/prisma/generated/app/index-browser.js +0 -736
- package/prisma/generated/app/index.d.ts +0 -62771
- package/prisma/generated/app/index.js +0 -779
- package/prisma/generated/app/libquery_engine-darwin-arm64.dylib.node +0 -0
- package/prisma/generated/app/libquery_engine-linux-musl-openssl-3.0.x.so.node +0 -0
- package/prisma/generated/app/package.json +0 -183
- package/prisma/generated/app/query_engine_bg.js +0 -2
- package/prisma/generated/app/query_engine_bg.wasm +0 -0
- package/prisma/generated/app/runtime/edge-esm.js +0 -34
- package/prisma/generated/app/runtime/edge.js +0 -34
- package/prisma/generated/app/runtime/index-browser.d.ts +0 -370
- package/prisma/generated/app/runtime/index-browser.js +0 -16
- package/prisma/generated/app/runtime/library.d.ts +0 -3977
- package/prisma/generated/app/runtime/library.js +0 -146
- package/prisma/generated/app/runtime/react-native.js +0 -83
- package/prisma/generated/app/runtime/wasm-compiler-edge.js +0 -84
- package/prisma/generated/app/runtime/wasm-engine-edge.js +0 -36
- package/prisma/generated/app/schema.prisma +0 -921
- package/prisma/generated/app/wasm-edge-light-loader.mjs +0 -4
- package/prisma/generated/app/wasm-worker-loader.mjs +0 -4
- package/prisma/generated/app/wasm.d.ts +0 -1
- package/prisma/generated/app/wasm.js +0 -761
- package/prisma/generated/law/client.d.ts +0 -1
- package/prisma/generated/law/client.js +0 -4
- package/prisma/generated/law/default.d.ts +0 -1
- package/prisma/generated/law/default.js +0 -4
- package/prisma/generated/law/edge.d.ts +0 -1
- package/prisma/generated/law/edge.js +0 -256
- package/prisma/generated/law/index-browser.js +0 -238
- package/prisma/generated/law/index.d.ts +0 -6868
- package/prisma/generated/law/index.js +0 -281
- package/prisma/generated/law/libquery_engine-darwin-arm64.dylib.node +0 -0
- package/prisma/generated/law/libquery_engine-linux-musl-openssl-3.0.x.so.node +0 -0
- package/prisma/generated/law/package.json +0 -183
- package/prisma/generated/law/query_engine_bg.js +0 -2
- package/prisma/generated/law/query_engine_bg.wasm +0 -0
- package/prisma/generated/law/runtime/edge-esm.js +0 -34
- package/prisma/generated/law/runtime/edge.js +0 -34
- package/prisma/generated/law/runtime/index-browser.d.ts +0 -370
- package/prisma/generated/law/runtime/index-browser.js +0 -16
- package/prisma/generated/law/runtime/library.d.ts +0 -3977
- package/prisma/generated/law/runtime/library.js +0 -146
- package/prisma/generated/law/runtime/react-native.js +0 -83
- package/prisma/generated/law/runtime/wasm-compiler-edge.js +0 -84
- package/prisma/generated/law/runtime/wasm-engine-edge.js +0 -36
- package/prisma/generated/law/schema.prisma +0 -82
- package/prisma/generated/law/wasm-edge-light-loader.mjs +0 -4
- package/prisma/generated/law/wasm-worker-loader.mjs +0 -4
- package/prisma/generated/law/wasm.d.ts +0 -1
- package/prisma/generated/law/wasm.js +0 -263
|
@@ -1,921 +0,0 @@
|
|
|
1
|
-
generator client {
|
|
2
|
-
provider = "prisma-client-js"
|
|
3
|
-
output = "./generated/app"
|
|
4
|
-
binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
datasource db {
|
|
8
|
-
provider = "postgresql"
|
|
9
|
-
url = env("POSTGRES_PRISMA_URL")
|
|
10
|
-
directUrl = env("POSTGRES_URL_NON_POOLING")
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
model Account {
|
|
14
|
-
id String @id @default(cuid())
|
|
15
|
-
userId String
|
|
16
|
-
type String
|
|
17
|
-
provider String
|
|
18
|
-
providerAccountId String
|
|
19
|
-
refresh_token String?
|
|
20
|
-
access_token String?
|
|
21
|
-
expires_at Int?
|
|
22
|
-
token_type String?
|
|
23
|
-
scope String?
|
|
24
|
-
id_token String?
|
|
25
|
-
session_state String?
|
|
26
|
-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
27
|
-
|
|
28
|
-
@@unique([provider, providerAccountId])
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
model User {
|
|
32
|
-
id String @id @default(cuid())
|
|
33
|
-
name String?
|
|
34
|
-
email String? @unique
|
|
35
|
-
emailVerified DateTime?
|
|
36
|
-
image String?
|
|
37
|
-
// Credentials authentication fields
|
|
38
|
-
password String? // Hashed password pre credentials login
|
|
39
|
-
createdAt DateTime @default(now())
|
|
40
|
-
agreedToTerms Boolean @default(false)
|
|
41
|
-
practiceArea String[]
|
|
42
|
-
lawFirm String?
|
|
43
|
-
yearsOfExperience Int?
|
|
44
|
-
// Nové polia pre schvalovanie používateľov
|
|
45
|
-
isApproved Boolean @default(false) // Či je používateľ schválený
|
|
46
|
-
isRejected Boolean @default(false) // Či je používateľ zamietnutý
|
|
47
|
-
approvedAt DateTime? // Kedy bol schválený
|
|
48
|
-
rejectedAt DateTime? // Kedy bol zamietnutý
|
|
49
|
-
approvedBy String? // ID admina, ktorý schválil
|
|
50
|
-
rejectedBy String? // ID admina, ktorý zamietol
|
|
51
|
-
rejectionReason String? // Dôvod zamietnutia
|
|
52
|
-
// Nové polia pre tracking a žiadosť
|
|
53
|
-
referralSource String? // Odkiaľ sa o nás dozvedel (Google, Facebook, LinkedIn, etc.)
|
|
54
|
-
applicationText String? // Text žiadosti o prihlásenie
|
|
55
|
-
// ✨ STRIPE FIELDS (B2C - len pre individuálnych používateľov)
|
|
56
|
-
subscriptionTier SubscriptionTier @default(FREE) // Aktuálny subscription tier (cache)
|
|
57
|
-
messageCount Int @default(10) // ✅ OPRAVENÉ z 100 na 10
|
|
58
|
-
messageCountResetAt DateTime? // Kedy sa má resetovať message count
|
|
59
|
-
adminGrantExpiresAt DateTime? // Kedy admin grant expiruje
|
|
60
|
-
// Relations
|
|
61
|
-
approvalRequest UserApprovalRequest?
|
|
62
|
-
stripeCustomer StripeCustomer? // ✨ B2C Stripe customer
|
|
63
|
-
ownedOrganizations Organization[] @relation("OrganizationOwner")
|
|
64
|
-
organizationMembers OrganizationMember[]
|
|
65
|
-
createdInvites OrganizationInvite[] @relation("InviteCreator")
|
|
66
|
-
accounts Account[]
|
|
67
|
-
answers Answer[]
|
|
68
|
-
conversations Conversation[]
|
|
69
|
-
feedbacks Feedback[]
|
|
70
|
-
pageViews PageView[]
|
|
71
|
-
sessions Session[]
|
|
72
|
-
workflowLogs WorkflowLog[]
|
|
73
|
-
verificationTokens VerificationToken[]
|
|
74
|
-
passwordResetTokens PasswordResetToken[]
|
|
75
|
-
canvasDocuments CanvasDocument[]
|
|
76
|
-
canvasDocumentVersions CanvasDocumentVersion[]
|
|
77
|
-
// Folder system relations
|
|
78
|
-
ownedFolders Folder[] @relation("FolderOwner")
|
|
79
|
-
addedFolderItems FolderItem[] @relation("FolderItemAdder")
|
|
80
|
-
folderActivities FolderActivity[] @relation("FolderActivityUser")
|
|
81
|
-
folderSharesReceived FolderShare[] @relation("FolderShareUser")
|
|
82
|
-
createdFolderShares FolderShare[] @relation("FolderShareCreator")
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Nový model pre žiadosti o schválenie
|
|
86
|
-
model UserApprovalRequest {
|
|
87
|
-
id String @id @default(cuid())
|
|
88
|
-
userId String @unique
|
|
89
|
-
status ApprovalStatus @default(PENDING)
|
|
90
|
-
submittedAt DateTime @default(now())
|
|
91
|
-
reviewedAt DateTime?
|
|
92
|
-
reviewedBy String? // ID admina, ktorý preskúmal žiadosť
|
|
93
|
-
notes String? // Poznámky admina
|
|
94
|
-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
95
|
-
|
|
96
|
-
@@index([status])
|
|
97
|
-
@@index([submittedAt])
|
|
98
|
-
@@index([reviewedAt])
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// ============================================
|
|
102
|
-
// ORGANIZATION MODELS (B2B)
|
|
103
|
-
// ============================================
|
|
104
|
-
|
|
105
|
-
// Organization = Právna kancelária / Firma
|
|
106
|
-
model Organization {
|
|
107
|
-
id String @id @default(cuid())
|
|
108
|
-
name String // "Advokátska kancelária XYZ s.r.o."
|
|
109
|
-
|
|
110
|
-
// Billing & Legal Information
|
|
111
|
-
companyNumber String? // IČO (Identifikačné číslo organizácie)
|
|
112
|
-
vatNumber String? // IČ DPH (VAT Number)
|
|
113
|
-
taxNumber String? // DIČ (Daňové identifikačné číslo)
|
|
114
|
-
legalForm String? // "s.r.o.", "a.s.", "v.o.s.", "k.s.", "SZČO"
|
|
115
|
-
billingEmail String
|
|
116
|
-
|
|
117
|
-
// Address
|
|
118
|
-
street String?
|
|
119
|
-
city String?
|
|
120
|
-
postalCode String?
|
|
121
|
-
country String @default("SK")
|
|
122
|
-
|
|
123
|
-
// Subscription (B2B)
|
|
124
|
-
subscriptionTier SubscriptionTier @default(FREE) // Tier organizácie (cache)
|
|
125
|
-
messageCount Int @default(0) // Spoločný pool správ pre všetkých členov
|
|
126
|
-
messageLimit Int @default(100) // Limit správ podľa tieru
|
|
127
|
-
messageCountResetAt DateTime? // Kedy sa má resetovať pool
|
|
128
|
-
adminGrantExpiresAt DateTime? // Kedy admin grant expiruje
|
|
129
|
-
|
|
130
|
-
// Settings
|
|
131
|
-
isActive Boolean @default(true)
|
|
132
|
-
maxMembers Int @default(5) // Max počet členov podľa tieru
|
|
133
|
-
|
|
134
|
-
// Relations
|
|
135
|
-
owner User @relation("OrganizationOwner", fields: [ownerId], references: [id])
|
|
136
|
-
ownerId String
|
|
137
|
-
members OrganizationMember[]
|
|
138
|
-
invites OrganizationInvite[]
|
|
139
|
-
stripeCustomer StripeCustomer?
|
|
140
|
-
folderShares FolderShare[]
|
|
141
|
-
|
|
142
|
-
createdAt DateTime @default(now())
|
|
143
|
-
updatedAt DateTime @updatedAt
|
|
144
|
-
|
|
145
|
-
@@index([ownerId])
|
|
146
|
-
@@index([vatNumber])
|
|
147
|
-
@@index([companyNumber])
|
|
148
|
-
@@index([subscriptionTier])
|
|
149
|
-
@@index([billingEmail])
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Many-to-Many: User ↔ Organization
|
|
153
|
-
model OrganizationMember {
|
|
154
|
-
id String @id @default(cuid())
|
|
155
|
-
organizationId String
|
|
156
|
-
userId String
|
|
157
|
-
role MemberRole @default(MEMBER)
|
|
158
|
-
joinedAt DateTime @default(now())
|
|
159
|
-
|
|
160
|
-
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
|
161
|
-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
162
|
-
|
|
163
|
-
@@unique([organizationId, userId])
|
|
164
|
-
@@index([organizationId])
|
|
165
|
-
@@index([userId])
|
|
166
|
-
@@index([role])
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Organization Invite System
|
|
170
|
-
model OrganizationInvite {
|
|
171
|
-
id String @id @default(cuid())
|
|
172
|
-
organizationId String
|
|
173
|
-
token String @unique
|
|
174
|
-
email String? // Optional: specific email invite
|
|
175
|
-
role MemberRole @default(MEMBER)
|
|
176
|
-
createdBy String
|
|
177
|
-
expiresAt DateTime
|
|
178
|
-
maxUses Int @default(1) // For multi-use invites
|
|
179
|
-
currentUses Int @default(0)
|
|
180
|
-
isActive Boolean @default(true)
|
|
181
|
-
usedAt DateTime? // Last usage timestamp
|
|
182
|
-
usedBy String? // Last user who used it
|
|
183
|
-
createdAt DateTime @default(now())
|
|
184
|
-
updatedAt DateTime @updatedAt
|
|
185
|
-
|
|
186
|
-
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
|
187
|
-
creator User @relation("InviteCreator", fields: [createdBy], references: [id])
|
|
188
|
-
|
|
189
|
-
@@index([token])
|
|
190
|
-
@@index([organizationId])
|
|
191
|
-
@@index([isActive])
|
|
192
|
-
@@index([expiresAt])
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
enum MemberRole {
|
|
196
|
-
OWNER // Zakladateľ/vlastník, plný prístup k billing a settings
|
|
197
|
-
ADMIN // Administrátor, môže pridávať/odoberať členov
|
|
198
|
-
MEMBER // Bežný člen, len používa systém
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
// ZJEDNODUŠENÝ Conversation - len metadata, bez duplikátov
|
|
202
|
-
model Conversation {
|
|
203
|
-
id String @id @default(cuid())
|
|
204
|
-
name String
|
|
205
|
-
userId String
|
|
206
|
-
isShareable Boolean @default(false)
|
|
207
|
-
shareUrl String? @unique
|
|
208
|
-
sharedAt DateTime?
|
|
209
|
-
createdAt DateTime @default(now())
|
|
210
|
-
updatedAt DateTime @updatedAt
|
|
211
|
-
summary String?
|
|
212
|
-
messagesSinceLastSummary Int? @default(0)
|
|
213
|
-
// Relácie
|
|
214
|
-
answers Answer[]
|
|
215
|
-
user User @relation(fields: [userId], references: [id])
|
|
216
|
-
workflowLogs WorkflowLog[]
|
|
217
|
-
canvasDocuments CanvasDocument[]
|
|
218
|
-
|
|
219
|
-
@@index([userId])
|
|
220
|
-
@@index([createdAt])
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Hlavný model - všetky správy, bez duplikátov
|
|
224
|
-
model Answer {
|
|
225
|
-
id String @id @default(cuid())
|
|
226
|
-
conversationId String
|
|
227
|
-
messageId String @unique
|
|
228
|
-
role Role
|
|
229
|
-
content String
|
|
230
|
-
question String?
|
|
231
|
-
answer String?
|
|
232
|
-
evaluation String?
|
|
233
|
-
isWelcome Boolean @default(false)
|
|
234
|
-
processingTime Int?
|
|
235
|
-
model String?
|
|
236
|
-
userId String?
|
|
237
|
-
createdAt DateTime @default(now())
|
|
238
|
-
updatedAt DateTime @updatedAt
|
|
239
|
-
// Relácie
|
|
240
|
-
conversation Conversation @relation(fields: [conversationId], references: [id], onDelete: Cascade)
|
|
241
|
-
user User? @relation(fields: [userId], references: [id])
|
|
242
|
-
feedback Feedback?
|
|
243
|
-
references Reference[]
|
|
244
|
-
metrics AnswerMetrics?
|
|
245
|
-
WorkflowLog WorkflowLog[]
|
|
246
|
-
files MessageFile[]
|
|
247
|
-
canvasDocumentId String? // No FK constraint - flexible document management
|
|
248
|
-
|
|
249
|
-
@@index([conversationId])
|
|
250
|
-
@@index([messageId])
|
|
251
|
-
@@index([role])
|
|
252
|
-
@@index([userId])
|
|
253
|
-
@@index([createdAt])
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
model MessageFile {
|
|
257
|
-
id String @id @default(cuid())
|
|
258
|
-
answerId String
|
|
259
|
-
fileName String
|
|
260
|
-
fileType String
|
|
261
|
-
base64Data String
|
|
262
|
-
uploadedAt DateTime @default(now())
|
|
263
|
-
answer Answer @relation(fields: [answerId], references: [id], onDelete: Cascade)
|
|
264
|
-
|
|
265
|
-
@@index([answerId])
|
|
266
|
-
@@index([fileType])
|
|
267
|
-
@@index([uploadedAt])
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// Nová tabuľka pre metriky odpovedí
|
|
271
|
-
model AnswerMetrics {
|
|
272
|
-
id String @id @default(cuid())
|
|
273
|
-
answerId String @unique
|
|
274
|
-
// Náklady
|
|
275
|
-
apiCost Float? // Celkové náklady (ai_cost + rag_cost)
|
|
276
|
-
aiCost Float? // Náklady len na AI provider volania
|
|
277
|
-
ragCost Float? // Náklady na RAG operácie
|
|
278
|
-
// Volania
|
|
279
|
-
apiCalls Int? // Celkový počet volaní
|
|
280
|
-
aiCalls Int? // Počet AI provider volaní
|
|
281
|
-
ragCalls Int? // Počet RAG operácií
|
|
282
|
-
// Čas a výkon
|
|
283
|
-
apiDuration Int? // Doba spracovania v ms
|
|
284
|
-
// AI Provider a Model
|
|
285
|
-
aiProvider String? // Hlavný AI provider
|
|
286
|
-
aiModel String? // Hlavný AI model
|
|
287
|
-
aiProvidersUsed String[] // Všetky použité AI providery
|
|
288
|
-
aiModelsUsed String[] // Všetky použité AI modely
|
|
289
|
-
// Timestamps
|
|
290
|
-
createdAt DateTime @default(now())
|
|
291
|
-
updatedAt DateTime @updatedAt
|
|
292
|
-
// Relations
|
|
293
|
-
answer Answer @relation(fields: [answerId], references: [id], onDelete: Cascade)
|
|
294
|
-
|
|
295
|
-
@@index([answerId])
|
|
296
|
-
@@index([apiCost])
|
|
297
|
-
@@index([apiDuration])
|
|
298
|
-
@@index([aiProvider])
|
|
299
|
-
@@index([createdAt])
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
model Feedback {
|
|
303
|
-
id String @id @default(cuid())
|
|
304
|
-
answerId String @unique
|
|
305
|
-
rating FeedbackRating
|
|
306
|
-
feedbackTypes String[]
|
|
307
|
-
customFeedback String?
|
|
308
|
-
userId String
|
|
309
|
-
messageContent String?
|
|
310
|
-
createdAt DateTime @default(now())
|
|
311
|
-
answer Answer @relation(fields: [answerId], references: [id], onDelete: Cascade)
|
|
312
|
-
user User @relation(fields: [userId], references: [id])
|
|
313
|
-
|
|
314
|
-
@@index([rating])
|
|
315
|
-
@@index([userId])
|
|
316
|
-
@@index([answerId])
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
// ZJEDNODUŠENÝ Reference - len na Answer, bez duplikátov
|
|
320
|
-
model Reference {
|
|
321
|
-
id String @id @default(cuid())
|
|
322
|
-
answerId String // Len answerId - konzistentné
|
|
323
|
-
type ReferenceType
|
|
324
|
-
title String
|
|
325
|
-
reference String
|
|
326
|
-
summary String?
|
|
327
|
-
url String?
|
|
328
|
-
uuid String?
|
|
329
|
-
relevance Float?
|
|
330
|
-
citationNumber Int?
|
|
331
|
-
metadata Json?
|
|
332
|
-
userId String?
|
|
333
|
-
createdAt DateTime @default(now())
|
|
334
|
-
// Relácie
|
|
335
|
-
answer Answer @relation(fields: [answerId], references: [id], onDelete: Cascade)
|
|
336
|
-
|
|
337
|
-
@@index([answerId])
|
|
338
|
-
@@index([type])
|
|
339
|
-
@@index([reference])
|
|
340
|
-
@@index([userId])
|
|
341
|
-
@@index([createdAt])
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
model PageView {
|
|
345
|
-
id String @id @default(cuid())
|
|
346
|
-
userId String?
|
|
347
|
-
sessionId String?
|
|
348
|
-
page String
|
|
349
|
-
path String
|
|
350
|
-
referrer String?
|
|
351
|
-
userAgent String?
|
|
352
|
-
ipAddress String?
|
|
353
|
-
country String?
|
|
354
|
-
city String?
|
|
355
|
-
deviceType String?
|
|
356
|
-
browser String?
|
|
357
|
-
os String?
|
|
358
|
-
screenSize String?
|
|
359
|
-
language String?
|
|
360
|
-
timeOnPage Int?
|
|
361
|
-
isBounce Boolean @default(true)
|
|
362
|
-
createdAt DateTime @default(now())
|
|
363
|
-
session Session? @relation(fields: [sessionId], references: [sessionId], onDelete: SetNull)
|
|
364
|
-
user User? @relation(fields: [userId], references: [id])
|
|
365
|
-
|
|
366
|
-
@@index([userId])
|
|
367
|
-
@@index([sessionId])
|
|
368
|
-
@@index([page])
|
|
369
|
-
@@index([createdAt])
|
|
370
|
-
@@index([country])
|
|
371
|
-
@@index([deviceType])
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
model Session {
|
|
375
|
-
id String @id @default(cuid())
|
|
376
|
-
sessionId String @unique
|
|
377
|
-
userId String?
|
|
378
|
-
startedAt DateTime @default(now())
|
|
379
|
-
endedAt DateTime?
|
|
380
|
-
duration Int?
|
|
381
|
-
pageViews PageView[]
|
|
382
|
-
user User? @relation(fields: [userId], references: [id])
|
|
383
|
-
workflowLogs WorkflowLog[]
|
|
384
|
-
|
|
385
|
-
@@index([userId])
|
|
386
|
-
@@index([startedAt])
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
// ============================================
|
|
390
|
-
// STRIPE INTEGRATION MODELS
|
|
391
|
-
// ============================================
|
|
392
|
-
|
|
393
|
-
// Stripe Customer - polymorphic relation (User OR Organization)
|
|
394
|
-
model StripeCustomer {
|
|
395
|
-
id String @id @default(cuid())
|
|
396
|
-
|
|
397
|
-
// ✅ Polymorphic relation - buď User (B2C) alebo Organization (B2B)
|
|
398
|
-
userId String? @unique // B2C: Individuálny používateľ
|
|
399
|
-
organizationId String? @unique // B2B: Organizácia
|
|
400
|
-
|
|
401
|
-
stripeCustomerId String @unique
|
|
402
|
-
email String
|
|
403
|
-
name String?
|
|
404
|
-
|
|
405
|
-
// Billing details (Stripe Address & Tax IDs)
|
|
406
|
-
billingAddress Json? // Stripe Address object
|
|
407
|
-
taxIds Json? // Stripe Tax IDs array (VAT, etc.)
|
|
408
|
-
|
|
409
|
-
createdAt DateTime @default(now())
|
|
410
|
-
updatedAt DateTime @updatedAt
|
|
411
|
-
|
|
412
|
-
// Relations
|
|
413
|
-
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
414
|
-
organization Organization? @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
|
415
|
-
subscriptions StripeSubscription[]
|
|
416
|
-
payments StripePayment[]
|
|
417
|
-
|
|
418
|
-
@@index([stripeCustomerId])
|
|
419
|
-
@@index([userId])
|
|
420
|
-
@@index([organizationId])
|
|
421
|
-
@@index([email])
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// Stripe Subscription - sledovanie predplatného (User alebo Organization)
|
|
425
|
-
model StripeSubscription {
|
|
426
|
-
id String @id @default(cuid())
|
|
427
|
-
|
|
428
|
-
// ✅ FIX: customerId = FK na StripeCustomer.id (nie stripeCustomerId!)
|
|
429
|
-
customerId String // FK na StripeCustomer.id
|
|
430
|
-
stripeCustomerId String // Stripe ID (pre logging/redundancia)
|
|
431
|
-
stripeSubscriptionId String @unique
|
|
432
|
-
stripePriceId String
|
|
433
|
-
stripeProductId String
|
|
434
|
-
|
|
435
|
-
status SubscriptionStatus
|
|
436
|
-
tier SubscriptionTier @default(FREE)
|
|
437
|
-
billingInterval BillingInterval @default(MONTHLY) // Monthly or Yearly billing
|
|
438
|
-
|
|
439
|
-
currentPeriodStart DateTime
|
|
440
|
-
currentPeriodEnd DateTime
|
|
441
|
-
cancelAtPeriodEnd Boolean @default(false)
|
|
442
|
-
canceledAt DateTime?
|
|
443
|
-
|
|
444
|
-
trialStart DateTime?
|
|
445
|
-
trialEnd DateTime?
|
|
446
|
-
|
|
447
|
-
// Additional fields
|
|
448
|
-
quantity Int @default(1) // Počet seats (pre LAW_FIRM/ENTERPRISE tier)
|
|
449
|
-
defaultPaymentMethodId String? // Stripe payment method ID
|
|
450
|
-
|
|
451
|
-
metadata Json? // Dodatočné Stripe metadata
|
|
452
|
-
createdAt DateTime @default(now())
|
|
453
|
-
updatedAt DateTime @updatedAt
|
|
454
|
-
|
|
455
|
-
// ✅ FIX: Relácia na customerId (interné ID), nie stripeCustomerId (Stripe ID)
|
|
456
|
-
customer StripeCustomer @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
|
457
|
-
|
|
458
|
-
@@index([stripeSubscriptionId])
|
|
459
|
-
@@index([customerId])
|
|
460
|
-
@@index([stripeCustomerId])
|
|
461
|
-
@@index([status])
|
|
462
|
-
@@index([tier])
|
|
463
|
-
@@index([billingInterval])
|
|
464
|
-
@@index([currentPeriodEnd])
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
// Stripe Event - prevencia duplicitného spracovania webhookov (idempotencia)
|
|
468
|
-
model StripeEvent {
|
|
469
|
-
id String @id @default(cuid())
|
|
470
|
-
eventId String @unique // Stripe event ID
|
|
471
|
-
type String // Typ eventu (napr. 'checkout.session.completed')
|
|
472
|
-
data Json // Úplné event data pre debugging
|
|
473
|
-
processed Boolean @default(false)
|
|
474
|
-
processedAt DateTime?
|
|
475
|
-
error String? // Uloženie chýb pri spracovaní
|
|
476
|
-
createdAt DateTime @default(now())
|
|
477
|
-
|
|
478
|
-
@@index([eventId])
|
|
479
|
-
@@index([processed])
|
|
480
|
-
@@index([type])
|
|
481
|
-
@@index([createdAt])
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
// Stripe Payment - sledovanie jednotlivých platieb (voliteľné, pre detailnú analytiku)
|
|
485
|
-
model StripePayment {
|
|
486
|
-
id String @id @default(cuid())
|
|
487
|
-
|
|
488
|
-
// ✅ FIX: Pridaná relácia na StripeCustomer
|
|
489
|
-
customerId String
|
|
490
|
-
stripePaymentId String @unique
|
|
491
|
-
stripeCustomerId String // Redundantné, ale OK pre logging
|
|
492
|
-
|
|
493
|
-
amount Int // Suma v centoch
|
|
494
|
-
currency String @default("eur")
|
|
495
|
-
status String // succeeded, failed, pending
|
|
496
|
-
paymentMethod String? // card, sepa_debit, atď.
|
|
497
|
-
description String?
|
|
498
|
-
|
|
499
|
-
// Invoice info
|
|
500
|
-
invoiceId String? // Stripe Invoice ID
|
|
501
|
-
invoiceUrl String? // URL na faktúru
|
|
502
|
-
|
|
503
|
-
metadata Json?
|
|
504
|
-
createdAt DateTime @default(now())
|
|
505
|
-
|
|
506
|
-
// ✅ Relácia na StripeCustomer
|
|
507
|
-
customer StripeCustomer @relation(fields: [customerId], references: [id], onDelete: Cascade)
|
|
508
|
-
|
|
509
|
-
@@index([stripePaymentId])
|
|
510
|
-
@@index([customerId])
|
|
511
|
-
@@index([stripeCustomerId])
|
|
512
|
-
@@index([status])
|
|
513
|
-
@@index([createdAt])
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
// ============================================
|
|
517
|
-
// ENUMS
|
|
518
|
-
// ============================================
|
|
519
|
-
|
|
520
|
-
enum Role {
|
|
521
|
-
USER
|
|
522
|
-
ASSISTANT
|
|
523
|
-
SYSTEM
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
enum FeedbackRating {
|
|
527
|
-
LIKE
|
|
528
|
-
DISLIKE
|
|
529
|
-
NEUTRAL
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
enum ReferenceType {
|
|
533
|
-
LAW
|
|
534
|
-
CASE
|
|
535
|
-
REGULATION
|
|
536
|
-
DOCUMENT
|
|
537
|
-
OTHER
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
enum ApprovalStatus {
|
|
541
|
-
PENDING
|
|
542
|
-
APPROVED
|
|
543
|
-
REJECTED
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
// Stripe: Status predplatného
|
|
547
|
-
enum SubscriptionStatus {
|
|
548
|
-
ACTIVE // Predplatné je aktívne
|
|
549
|
-
CANCELED // Predplatné zrušené
|
|
550
|
-
INCOMPLETE // Iniciálna platba zlyhala
|
|
551
|
-
INCOMPLETE_EXPIRED // Neúplné predplatné expirované
|
|
552
|
-
PAST_DUE // Platba zlyhala, retry prebieha
|
|
553
|
-
TRIALING // V skúšobnom období
|
|
554
|
-
UNPAID // Platba zlyhala, žiadny retry
|
|
555
|
-
PAUSED // Predplatné pozastavené (Stripe feature)
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
// Stripe: Tier predplatného
|
|
559
|
-
enum SubscriptionTier {
|
|
560
|
-
FREE // Free tier (10 messages/month)
|
|
561
|
-
LAWYER // Lawyer tier (1000 messages/month, €29/month, 1 user)
|
|
562
|
-
LAWYER_PRO // Lawyer Pro tier (3000 messages/month, €49/month, 1 user) - RECOMMENDED
|
|
563
|
-
LAW_FIRM // Law Firm tier (10000 messages/month, €129/month, up to 5 users)
|
|
564
|
-
ENTERPRISE // Enterprise tier (unlimited messages, unlimited users, custom pricing)
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
// Stripe: Billing interval
|
|
568
|
-
enum BillingInterval {
|
|
569
|
-
MONTHLY // Monthly billing
|
|
570
|
-
YEARLY // Yearly billing (17% discount)
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
// Canvas Document Status
|
|
574
|
-
enum DocumentStatus {
|
|
575
|
-
DRAFT
|
|
576
|
-
SAVED
|
|
577
|
-
ARCHIVED
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// ============================================
|
|
581
|
-
// FOLDER SYSTEM ENUMS
|
|
582
|
-
// ============================================
|
|
583
|
-
|
|
584
|
-
// Folder item types (what can be stored in folders)
|
|
585
|
-
enum FolderItemType {
|
|
586
|
-
CONVERSATION
|
|
587
|
-
CANVAS_DOCUMENT
|
|
588
|
-
REFERENCE
|
|
589
|
-
ATTACHMENT
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
// Folder activity types (for timeline)
|
|
593
|
-
enum FolderActivityType {
|
|
594
|
-
FOLDER_CREATED
|
|
595
|
-
FOLDER_UPDATED
|
|
596
|
-
FOLDER_MOVED
|
|
597
|
-
FOLDER_ARCHIVED
|
|
598
|
-
ITEM_ADDED
|
|
599
|
-
ITEM_REMOVED
|
|
600
|
-
ITEM_UPDATED
|
|
601
|
-
SHARE_ADDED
|
|
602
|
-
SHARE_REMOVED
|
|
603
|
-
USER_MESSAGE
|
|
604
|
-
USER_NOTE
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
// Folder permission levels
|
|
608
|
-
enum FolderPermission {
|
|
609
|
-
VIEW
|
|
610
|
-
EDIT
|
|
611
|
-
ADMIN
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
// Nový model pre logovanie admin akcií
|
|
615
|
-
model AdminActionLog {
|
|
616
|
-
id String @id @default(cuid())
|
|
617
|
-
action String // APPROVE_USER, REJECT_USER, etc.
|
|
618
|
-
targetUserId String // ID používateľa, na ktorého sa akcia vzťahuje
|
|
619
|
-
adminEmail String // E-mail admina, ktorý vykonal akciu
|
|
620
|
-
details Json? // Ďalšie detaily akcie (reason, notes, etc.)
|
|
621
|
-
createdAt DateTime @default(now())
|
|
622
|
-
|
|
623
|
-
@@index([action])
|
|
624
|
-
@@index([targetUserId])
|
|
625
|
-
@@index([adminEmail])
|
|
626
|
-
@@index([createdAt])
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
model WorkflowLog {
|
|
630
|
-
id String @id @default(cuid()) // Added @default(cuid())
|
|
631
|
-
conversationId String
|
|
632
|
-
messageId String?
|
|
633
|
-
userId String? // Made optional to preserve logs when users are deleted
|
|
634
|
-
sessionId String? // Removed @unique to allow multiple workflows per session
|
|
635
|
-
startedAt DateTime @default(now())
|
|
636
|
-
completedAt DateTime?
|
|
637
|
-
status WorkflowStatus @default(IN_PROGRESS)
|
|
638
|
-
totalDuration Int? // milliseconds
|
|
639
|
-
error String?
|
|
640
|
-
metadata Json?
|
|
641
|
-
steps WorkflowStep[] // Renamed from WorkflowStep to steps (lowerCamel, plural)
|
|
642
|
-
conversation Conversation @relation(fields: [conversationId], references: [id], onDelete: Cascade)
|
|
643
|
-
user User? @relation(fields: [userId], references: [id], onDelete: SetNull)
|
|
644
|
-
session Session? @relation(fields: [sessionId], references: [sessionId], onDelete: SetNull)
|
|
645
|
-
answer Answer? @relation(fields: [messageId], references: [messageId])
|
|
646
|
-
|
|
647
|
-
@@index([conversationId])
|
|
648
|
-
@@index([userId])
|
|
649
|
-
@@index([sessionId])
|
|
650
|
-
@@index([startedAt])
|
|
651
|
-
@@index([status])
|
|
652
|
-
@@index([conversationId, startedAt]) // Composite index for timeline queries
|
|
653
|
-
@@index([messageId])
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
model WorkflowStep {
|
|
657
|
-
id String @id @default(cuid()) // Added @default(cuid())
|
|
658
|
-
workflowId String
|
|
659
|
-
stepName String // 'classify_question', 'rag_search', 'ai_processing', 'generate_response'
|
|
660
|
-
stepType StepType
|
|
661
|
-
startedAt DateTime @default(now())
|
|
662
|
-
completedAt DateTime?
|
|
663
|
-
duration Int? // milliseconds
|
|
664
|
-
status StepStatus @default(IN_PROGRESS)
|
|
665
|
-
inputData Json? // Sanitized input data
|
|
666
|
-
outputData Json? // Sanitized output data
|
|
667
|
-
error String?
|
|
668
|
-
metadata Json? // Provider used, model used, tokens, costs, etc.
|
|
669
|
-
workflow WorkflowLog @relation(fields: [workflowId], references: [id], onDelete: Cascade)
|
|
670
|
-
|
|
671
|
-
@@index([workflowId])
|
|
672
|
-
@@index([stepName])
|
|
673
|
-
@@index([stepType])
|
|
674
|
-
@@index([startedAt])
|
|
675
|
-
@@index([status])
|
|
676
|
-
@@index([workflowId, startedAt]) // Composite index for timeline queries
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
enum WorkflowStatus {
|
|
680
|
-
IN_PROGRESS
|
|
681
|
-
COMPLETED
|
|
682
|
-
FAILED
|
|
683
|
-
CANCELLED
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
enum StepStatus {
|
|
687
|
-
IN_PROGRESS
|
|
688
|
-
COMPLETED
|
|
689
|
-
FAILED
|
|
690
|
-
SKIPPED
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
enum StepType {
|
|
694
|
-
CLASSIFICATION
|
|
695
|
-
RAG_RETRIEVAL
|
|
696
|
-
AI_PROCESSING
|
|
697
|
-
RESPONSE_GENERATION
|
|
698
|
-
DATA_PERSISTENCE
|
|
699
|
-
ERROR_HANDLING
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
// Email verification tokens
|
|
703
|
-
model VerificationToken {
|
|
704
|
-
id String @id @default(cuid())
|
|
705
|
-
userId String
|
|
706
|
-
token String @unique
|
|
707
|
-
expires DateTime
|
|
708
|
-
createdAt DateTime @default(now())
|
|
709
|
-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
710
|
-
|
|
711
|
-
@@index([token])
|
|
712
|
-
@@index([userId])
|
|
713
|
-
@@index([expires])
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
// Password reset tokens
|
|
717
|
-
model PasswordResetToken {
|
|
718
|
-
id String @id @default(cuid())
|
|
719
|
-
userId String
|
|
720
|
-
token String @unique
|
|
721
|
-
expires DateTime
|
|
722
|
-
createdAt DateTime @default(now())
|
|
723
|
-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
|
724
|
-
|
|
725
|
-
@@index([token])
|
|
726
|
-
@@index([userId])
|
|
727
|
-
@@index([expires])
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
// ============================================
|
|
731
|
-
// CANVAS DOCUMENT MODELS
|
|
732
|
-
// ============================================
|
|
733
|
-
|
|
734
|
-
model CanvasDocument {
|
|
735
|
-
id String @id @default(cuid())
|
|
736
|
-
userId String
|
|
737
|
-
title String
|
|
738
|
-
status DocumentStatus @default(DRAFT)
|
|
739
|
-
createdAt DateTime @default(now())
|
|
740
|
-
updatedAt DateTime @updatedAt
|
|
741
|
-
originConversationId String?
|
|
742
|
-
originAnswerId String? // No FK constraint - async save reference
|
|
743
|
-
currentVersionId String? @unique
|
|
744
|
-
|
|
745
|
-
// Relations
|
|
746
|
-
user User @relation(fields: [userId], references: [id], onDelete: Restrict)
|
|
747
|
-
originConversation Conversation? @relation(fields: [originConversationId], references: [id], onDelete: SetNull)
|
|
748
|
-
currentVersion CanvasDocumentVersion? @relation("CurrentVersion", fields: [currentVersionId], references: [id], onDelete: SetNull)
|
|
749
|
-
versions CanvasDocumentVersion[] @relation("DocumentVersions")
|
|
750
|
-
|
|
751
|
-
@@index([userId])
|
|
752
|
-
@@index([originConversationId])
|
|
753
|
-
@@index([status])
|
|
754
|
-
@@index([createdAt])
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
model CanvasDocumentVersion {
|
|
758
|
-
id String @id @default(cuid())
|
|
759
|
-
documentId String
|
|
760
|
-
versionNumber Int
|
|
761
|
-
title String
|
|
762
|
-
markdownContent String
|
|
763
|
-
createdAt DateTime @default(now())
|
|
764
|
-
createdBy String
|
|
765
|
-
regenerationPrompt String?
|
|
766
|
-
parentVersionId String?
|
|
767
|
-
|
|
768
|
-
// Relations
|
|
769
|
-
document CanvasDocument @relation("DocumentVersions", fields: [documentId], references: [id], onDelete: Cascade)
|
|
770
|
-
creator User @relation(fields: [createdBy], references: [id], onDelete: Restrict)
|
|
771
|
-
parentVersion CanvasDocumentVersion? @relation("VersionHistory", fields: [parentVersionId], references: [id], onDelete: SetNull)
|
|
772
|
-
childVersions CanvasDocumentVersion[] @relation("VersionHistory")
|
|
773
|
-
currentForDocument CanvasDocument? @relation("CurrentVersion")
|
|
774
|
-
|
|
775
|
-
@@unique([documentId, versionNumber])
|
|
776
|
-
@@index([documentId])
|
|
777
|
-
@@index([createdBy])
|
|
778
|
-
@@index([createdAt])
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
// ============================================
|
|
782
|
-
// FOLDER SYSTEM MODELS
|
|
783
|
-
// ============================================
|
|
784
|
-
|
|
785
|
-
// Main folder entity with hierarchy support via parentId
|
|
786
|
-
// Uses materialized path pattern for efficient hierarchy queries
|
|
787
|
-
model Folder {
|
|
788
|
-
id String @id @default(cuid())
|
|
789
|
-
name String
|
|
790
|
-
description String?
|
|
791
|
-
color String? @default("#6366f1")
|
|
792
|
-
icon String? @default("folder")
|
|
793
|
-
|
|
794
|
-
// Ownership (always user-owned)
|
|
795
|
-
ownerId String
|
|
796
|
-
|
|
797
|
-
// Hierarchy
|
|
798
|
-
parentId String?
|
|
799
|
-
rootFolderId String? // NULL for root folders, points to top-level ancestor
|
|
800
|
-
path String @default("/") // Materialized path: "/parentId/grandparentId/..."
|
|
801
|
-
depth Int @default(0)
|
|
802
|
-
|
|
803
|
-
// Metadata
|
|
804
|
-
sortOrder Int @default(0)
|
|
805
|
-
isArchived Boolean @default(false)
|
|
806
|
-
createdAt DateTime @default(now())
|
|
807
|
-
updatedAt DateTime @updatedAt
|
|
808
|
-
|
|
809
|
-
// Relations
|
|
810
|
-
owner User @relation("FolderOwner", fields: [ownerId], references: [id], onDelete: Cascade)
|
|
811
|
-
parent Folder? @relation("FolderHierarchy", fields: [parentId], references: [id], onDelete: Cascade)
|
|
812
|
-
children Folder[] @relation("FolderHierarchy")
|
|
813
|
-
items FolderItem[]
|
|
814
|
-
activities FolderActivity[]
|
|
815
|
-
shares FolderShare[]
|
|
816
|
-
|
|
817
|
-
@@index([ownerId])
|
|
818
|
-
@@index([parentId])
|
|
819
|
-
@@index([rootFolderId])
|
|
820
|
-
@@index([path])
|
|
821
|
-
@@index([isArchived])
|
|
822
|
-
@@index([ownerId, isArchived])
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
// Links entities (conversations, documents, etc.) to folders
|
|
826
|
-
// Polymorphic: entityType + entityId point to any supported entity
|
|
827
|
-
model FolderItem {
|
|
828
|
-
id String @id @default(cuid())
|
|
829
|
-
folderId String
|
|
830
|
-
|
|
831
|
-
// Polymorphic reference
|
|
832
|
-
entityType FolderItemType
|
|
833
|
-
entityId String
|
|
834
|
-
|
|
835
|
-
// Optional metadata override
|
|
836
|
-
displayName String?
|
|
837
|
-
notes String?
|
|
838
|
-
|
|
839
|
-
// Denormalized for efficient hierarchy queries
|
|
840
|
-
rootFolderId String?
|
|
841
|
-
|
|
842
|
-
// Tracking
|
|
843
|
-
addedById String
|
|
844
|
-
sortOrder Int @default(0)
|
|
845
|
-
createdAt DateTime @default(now())
|
|
846
|
-
updatedAt DateTime @updatedAt
|
|
847
|
-
|
|
848
|
-
// Relations
|
|
849
|
-
folder Folder @relation(fields: [folderId], references: [id], onDelete: Cascade)
|
|
850
|
-
addedBy User @relation("FolderItemAdder", fields: [addedById], references: [id], onDelete: Restrict)
|
|
851
|
-
|
|
852
|
-
@@unique([folderId, entityType, entityId])
|
|
853
|
-
@@index([folderId])
|
|
854
|
-
@@index([entityType, entityId])
|
|
855
|
-
@@index([rootFolderId])
|
|
856
|
-
@@index([addedById])
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
// Timeline entries for folders (system events + user messages)
|
|
860
|
-
// Opening ANY folder shows ALL activities from the entire folder tree
|
|
861
|
-
model FolderActivity {
|
|
862
|
-
id String @id @default(cuid())
|
|
863
|
-
folderId String
|
|
864
|
-
|
|
865
|
-
// Denormalized for cross-folder timeline queries
|
|
866
|
-
rootFolderId String?
|
|
867
|
-
|
|
868
|
-
// Activity details
|
|
869
|
-
activityType FolderActivityType
|
|
870
|
-
userId String
|
|
871
|
-
content String? // For USER_MESSAGE, USER_NOTE types
|
|
872
|
-
metadata Json? // For system event details
|
|
873
|
-
relatedItemId String? // Optional reference to FolderItem
|
|
874
|
-
|
|
875
|
-
// Timestamp
|
|
876
|
-
createdAt DateTime @default(now())
|
|
877
|
-
|
|
878
|
-
// Relations
|
|
879
|
-
folder Folder @relation(fields: [folderId], references: [id], onDelete: Cascade)
|
|
880
|
-
user User @relation("FolderActivityUser", fields: [userId], references: [id], onDelete: Restrict)
|
|
881
|
-
|
|
882
|
-
@@index([folderId])
|
|
883
|
-
@@index([rootFolderId])
|
|
884
|
-
@@index([userId])
|
|
885
|
-
@@index([activityType])
|
|
886
|
-
@@index([createdAt])
|
|
887
|
-
@@index([rootFolderId, createdAt(sort: Desc)])
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
// Sharing permissions for folders
|
|
891
|
-
// Can share with individual user OR entire organization (not both)
|
|
892
|
-
model FolderShare {
|
|
893
|
-
id String @id @default(cuid())
|
|
894
|
-
folderId String
|
|
895
|
-
|
|
896
|
-
// Share target (either user OR organization, enforced by application logic)
|
|
897
|
-
userId String?
|
|
898
|
-
organizationId String?
|
|
899
|
-
|
|
900
|
-
// Permission level
|
|
901
|
-
permission FolderPermission @default(VIEW)
|
|
902
|
-
|
|
903
|
-
// Sharing metadata
|
|
904
|
-
sharedById String
|
|
905
|
-
sharedAt DateTime @default(now())
|
|
906
|
-
expiresAt DateTime?
|
|
907
|
-
|
|
908
|
-
// Relations
|
|
909
|
-
folder Folder @relation(fields: [folderId], references: [id], onDelete: Cascade)
|
|
910
|
-
user User? @relation("FolderShareUser", fields: [userId], references: [id], onDelete: Cascade)
|
|
911
|
-
organization Organization? @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
|
912
|
-
sharedBy User @relation("FolderShareCreator", fields: [sharedById], references: [id], onDelete: Restrict)
|
|
913
|
-
|
|
914
|
-
// Partial unique indexes for nullable columns
|
|
915
|
-
@@unique([folderId, userId])
|
|
916
|
-
@@unique([folderId, organizationId])
|
|
917
|
-
@@index([folderId])
|
|
918
|
-
@@index([userId])
|
|
919
|
-
@@index([organizationId])
|
|
920
|
-
@@index([sharedById])
|
|
921
|
-
}
|