-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.prisma
598 lines (527 loc) · 17.9 KB
/
schema.prisma
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
// This is your Prisma schema file, learn more about it in the docs: https://pris.ly/d/prisma-schema
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
generator client {
provider = "prisma-client-js"
}
// This is an optional zod helper script:
// It will generate zod schemas based on this prisma-schema in `/db/zod-schema-inspiration`
// We can use those, to improve our own zod schema files.
// However, we cannot have this active all the time, due to an issue with blitz.
// How to use:
// 1. Remove comment below
// 2. Use `npx blitz prisma generate` (mind the `x`)
// 3. Copy what you need to your own schema
// 4. Revert (1)
//
// generator zod {
// provider = "zod-prisma"
// output = "./zod-schema-inspiration"
// relationModel = true
// modelCase = "PascalCase"
// modelSuffix = "Model"
// useDecimalJs = true
// imports = null
// prismaJsonNullability = true
// }
// --------------------------------------
model User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
email String @unique
hashedPassword String?
role UserRoleEnum @default(USER)
firstName String
lastName String
phone String?
institution String? // Organisation / Kommune
tokens Token[]
sessions Session[]
projects Project[]
subsections Subsection[]
memberships Membership[]
Subsubsection Subsubsection[]
invites Invite[]
logEntries LogEntry[]
SurveyResponseComment SurveyResponseComment[]
}
enum UserRoleEnum {
USER
ADMIN
}
model Invite {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
token String @unique
status InviteStatusEnum @default(PENDING)
//
email String
role MembershipRoleEnum @default(VIEWER)
//
projectId Int
project Project @relation(fields: [projectId], references: [id])
inviterId Int
inviter User @relation(fields: [inviterId], references: [id])
@@unique([email, projectId])
}
enum InviteStatusEnum {
PENDING
ACCEPTED
EXPIRED
}
model Session {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
expiresAt DateTime?
handle String @unique
hashedSessionToken String?
antiCSRFToken String?
publicData String?
privateData String?
user User? @relation(fields: [userId], references: [id])
userId Int?
}
model Token {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
hashedToken String
type String
// See note below about TokenType enum
// type TokenType
expiresAt DateTime
sentTo String
user User @relation(fields: [userId], references: [id])
userId Int
@@unique([hashedToken, type])
}
// NOTE: It's highly recommended to use an enum for the token type
// but enums only work in Postgres.
// See: https://blitzjs.com/docs/database-overview#switch-to-postgre-sql
// enum TokenType {
// RESET_PASSWORD
// }
model Project {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String @unique // shortTitle and URL Slug
subTitle String?
description String?
logoSrc String?
partnerLogoSrcs String[]
exportEnabled Boolean @default(false)
//
manager User? @relation(fields: [managerId], references: [id])
managerId Int?
surveyResponseTopics SurveyResponseTopic[]
subsections Subsection[]
calendarEntries CalendarEntry[]
contacts Contact[]
uploads Upload[]
memberships Membership[]
operators Operator[]
surveys Survey[]
qualityLevels QualityLevel[]
subsubsectionStatuses SubsubsectionStatus[]
subsubsectionTasks SubsubsectionTask[]
subsubsectionInfras SubsubsectionInfra[]
subsubsectionSpecials SubsubsectionSpecial[]
networkHierarchies NetworkHierarchy[]
invites Invite[]
logEntries LogEntry[]
}
model Membership {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
project Project @relation(fields: [projectId], references: [id])
projectId Int
user User @relation(fields: [userId], references: [id])
userId Int
role MembershipRoleEnum @default(VIEWER)
@@unique([projectId, userId])
}
enum MembershipRoleEnum {
VIEWER
EDITOR
}
model CalendarEntry {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
title String
startAt DateTime
locationName String?
locationUrl String?
description String?
project Project @relation(fields: [projectId], references: [id])
projectId Int
}
model Contact {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
firstName String?
lastName String
email String
note String?
phone String?
role String?
project Project @relation(fields: [projectId], references: [id])
projectId Int
@@unique([projectId, email])
}
enum LabelPositionEnum {
top
topRight
right
bottomRight
bottom
bottomLeft
left
topLeft
}
model Operator {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
subsections Subsection[]
surveyResponses SurveyResponse[]
@@unique([projectId, slug])
}
model Subsection {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
start String
end String
order Int @default(autoincrement())
geometry Json
labelPos LabelPositionEnum @default(top)
description String?
lengthKm Float // Kilometer
priority PriorityEnum @default(OPEN) // Priorität
estimatedCompletionDateString String? // Jahresquartal der geplanten Fertigstellung als string Form "1-2023"
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
manager User? @relation(fields: [managerId], references: [id])
managerId Int?
operator Operator? @relation(fields: [operatorId], references: [id])
operatorId Int?
networkHierarchy NetworkHierarchy? @relation(fields: [networkHierarchyId], references: [id])
networkHierarchyId Int?
SubsubsectionStatus SubsubsectionStatus? @relation(fields: [subsubsectionStatusId], references: [id])
subsubsectionStatusId Int?
//
subsubsections Subsubsection[]
stakeholdernotes Stakeholdernote[]
uploads Upload[]
@@unique([projectId, slug])
@@unique([projectId, order])
}
enum PriorityEnum {
OPEN
TOP //sehr hoch, hoch, mittel, niedrig
HIGH
MEDIUM
LOW
}
model NetworkHierarchy {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
subsections Subsection[]
@@unique([projectId, slug])
}
model Subsubsection {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
subTitle String?
type SubsubsectionTypeEnum @default(ROUTE) // Führungform
geometry Json
labelPos LabelPositionEnum @default(top)
task String? // Maßnahmentyp - UNUSED
lengthKm Float // Kilometer
width Float? // Meter
widthExisting Float? // Meter
description String? // Anmerkungen
mapillaryKey String?
isExistingInfra Boolean? @default(false) // Bestandsführung
maxSpeed Float? // Maximalgeschwindigkeit
trafficLoad Int? // Verkehrsbelastung
trafficLoadDate DateTime? // Datum der Verkehrsbelastung
planningPeriod Float? // Planungsdauer in Monaten
constructionPeriod Float? // Baudauer in Monaten
estimatedCompletionDate DateTime? // Jahresquartal der geplanten Fertigstellung als string Form "1-2023"
//
costEstimate Float? // Euro
//
planningCosts Float? // Planungskosten
deliveryCosts Float? // Lieferkosten
constructionCosts Float? // Baukosten
landAcquisitionCosts Float? // Grunderwerbskosten
expensesOfficialOrders Float? // Ausgaben aufgrund behördlicher Anordnungen
expensesTechnicalVerification Float? // Ausgaben für den fachtechnischen Nachweis usw.
//
nonEligibleExpenses Float? // Nicht zuwendungsfähige Ausgaben
//
revenuesEconomicIncome Float? // Erlöse und wirtschafltiche Einnahmen
contributionsThirdParties Float? // Beiträge Dritter
grantsOtherFunding Float? // Zuwendungen aus anderen Förderprogrammen
ownFunds Float? // Einsatz Eigenmittel
qualityLevel QualityLevel? @relation(fields: [qualityLevelId], references: [id])
qualityLevelId Int?
//
manager User? @relation(fields: [managerId], references: [id])
managerId Int?
//
subsection Subsection @relation(fields: [subsectionId], references: [id])
subsectionId Int
//
uploads Upload[]
//
SubsubsectionStatus SubsubsectionStatus? @relation(fields: [subsubsectionStatusId], references: [id])
subsubsectionStatusId Int?
//
SubsubsectionTask SubsubsectionTask? @relation(fields: [subsubsectionTaskId], references: [id])
subsubsectionTaskId Int?
//
SubsubsectionInfra SubsubsectionInfra? @relation(fields: [subsubsectionInfraId], references: [id])
subsubsectionInfraId Int?
specialFeatures SubsubsectionSpecial[]
@@unique([subsectionId, slug])
}
enum SubsubsectionTypeEnum {
ROUTE // Regelführung Strecke RF
AREA // Sonderführung Punkt (Bereich) SF
}
model QualityLevel {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
subsubsections Subsubsection[]
@@unique([projectId, slug])
}
model SubsubsectionStatus {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
subsubsections Subsubsection[]
Subsection Subsection[]
@@unique([projectId, slug])
}
// Maßnahmentyp
model SubsubsectionTask {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
subsubsections Subsubsection[]
@@unique([projectId, slug])
}
// Führungsform
model SubsubsectionInfra {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
subsubsections Subsubsection[]
@@unique([projectId, slug])
}
model SubsubsectionSpecial {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
slug String // shortTitle and URL Slug
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
//
subsubsections Subsubsection[]
@@unique([projectId, slug])
}
model Stakeholdernote {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
status StakeholdernoteStatusEnum @default(PENDING)
statusText String?
//
subsection Subsection @relation(fields: [subsectionId], references: [id])
subsectionId Int
}
enum StakeholdernoteStatusEnum {
PENDING
IN_PROGRESS
DONE
IRRELEVANT
}
model Upload {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
title String
externalUrl String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
subsection Subsection? @relation(fields: [subsectionId], references: [id])
subsectionId Int?
Subsubsection Subsubsection? @relation(fields: [subsubsectionId], references: [id])
subsubsectionId Int?
}
model Survey {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
startDate DateTime?
endDate DateTime?
slug String @unique
title String
active Boolean @default(false)
interestedParticipants Int?
surveyResultsUrl String?
//
projectId Int
project Project @relation(fields: [projectId], references: [id])
//
surveySessions SurveySession[]
}
model SurveySession {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
survey Survey @relation(fields: [surveyId], references: [id])
surveyId Int
//
responses SurveyResponse[]
}
model SurveyResponse {
id Int @id @default(autoincrement())
surveyPart Int
data String
status String?
note String?
source SurveyResponseSourceEnum @default(FORM)
//
surveySession SurveySession @relation(fields: [surveySessionId], references: [id])
surveySessionId Int
operatorId Int?
operator Operator? @relation(fields: [operatorId], references: [id])
//
surveyResponseTopics SurveyResponseTopicsOnSurveyResponses[]
surveyResponseComments SurveyResponseComment[]
}
enum SurveyResponseSourceEnum {
EMAIL
LETTER
FORM
}
model SurveyResponseTopic {
id Int @id @default(autoincrement())
title String
//
project Project @relation(fields: [projectId], references: [id])
projectId Int
surveyResponses SurveyResponseTopicsOnSurveyResponses[]
@@unique([title, projectId])
}
model SurveyResponseTopicsOnSurveyResponses {
surveyResponse SurveyResponse @relation(fields: [surveyResponseId], references: [id])
surveyResponseId Int
surveyResponseTopic SurveyResponseTopic @relation(fields: [surveyResponseTopicId], references: [id])
surveyResponseTopicId Int
@@id([surveyResponseId, surveyResponseTopicId])
}
model SurveyResponseComment {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
author User @relation(fields: [userId], references: [id])
userId Int
//
surveyResponse SurveyResponse @relation(fields: [surveyResponseId], references: [id], onDelete: Cascade)
surveyResponseId Int
//
body String
}
model LogEntry {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
//
userId Int?
user User? @relation(fields: [userId], references: [id])
projectId Int?
project Project? @relation(fields: [projectId], references: [id])
//
logLevel LogLevelEnum @default(INFO)
message String
context Json?
// Maybe later…
// @@index([createdAt])
// @@index([userId])
// @@index([projectId])
}
enum LogLevelEnum {
INFO
WARN
ERROR
}