-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.prisma
1197 lines (1045 loc) · 46.4 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
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
generator goprisma {
provider = "go run github.com/steebchen/prisma-client-go"
previewFeatures = ["fullTextSearch", "postgresqlExtensions"]
}
// See https://pothos-graphql.dev/docs/plugins/prisma#setup
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
extensions = [fuzzystrmatch, pgcrypto, unaccent, pg_trgm]
}
/// Users are the people who use the app
model User {
id String @id @default(dbgenerated("nanoid('u:')"))
uid String @unique @db.VarChar(255)
createdAt DateTime @default(now())
// School details
schoolServer String? @db.VarChar(255)
schoolUid String? @db.VarChar(255)
// email of the user from the school's LDAP
schoolEmail String? @db.VarChar(255)
email String @unique @db.VarChar(255)
otherEmails String[] @db.VarChar(255)
firstName String @db.VarChar(255)
lastName String @db.VarChar(255)
majorId String?
major Major? @relation(fields: [majorId], references: [id], onUpdate: Cascade, onDelete: Restrict)
minor Minor? @relation(fields: [minorId], references: [id])
minorId String?
graduationYear Int
apprentice Boolean @default(false)
address String @default("") @db.VarChar(255)
birthday DateTime?
description String @default("") @db.Text
nickname String @default("") @db.VarChar(255)
phone String @default("") @db.VarChar(255)
pictureFile String @default("") @db.VarChar(255)
links Link[]
godparentId String?
cededImageRightsToTVn7 Boolean @default(false)
enabledNotificationChannels NotificationChannel[] @default([Articles, Shotguns, Permissions, GroupBoard, GodparentRequests, Comments, Other])
latestVersionSeenInChangelog String @default("0.0.0")
bot Boolean @default(false)
// Not shown on profile, used to autofill Lydia payment request forms
lydiaPhone String @default("") @db.VarChar(255)
// Prevent these themes from being auto-deployed to the user
blockedThemes Theme[]
// Permissions
admin Boolean @default(false)
canEditGroups StudentAssociation[] @relation("studentAssociationGroupsEditor")
canAccessDocuments Boolean @default(false)
// Relationships
articles Article[]
groups GroupMember[]
credentials Credential[]
Reservation Registration[] @relation("author")
managedEvents EventManager[]
logs LogEntry[]
events Event[]
notificationSubscriptions NotificationSubscription[]
notifications Notification[]
godparent User? @relation("mentorship", fields: [godparentId], references: [id]) // Le parrain ou la marraine
godchildren User[] @relation("mentorship") // Les filleul(e)s
incomingGodparentRequests GodparentRequest[] @relation("godparent")
outgoingGodparentRequests GodparentRequest[] @relation("godchild")
passwordResets PasswordReset[]
emailChanges EmailChange[]
Announcement Announcement[]
contributions Contribution[]
verifications Registration[] @relation("verifiedBy")
oppositions Registration[] @relation("opposedBy")
cancellations Registration[] @relation("cancelledBy")
receivedBookings Registration[] @relation("beneficiaryOf")
documents Document[]
comments Comment[]
bannedFromEvents Event[] @relation("bannedFromEvents")
reactions Reaction[]
formAnswers Answer[]
createdForms Form[]
completedForms Form[] @relation("completedForms")
partiallyCompletedForms Form[] @relation("partiallyCompletedForms")
adminOfStudentAssociations StudentAssociation[] @relation("studentAssociationAdmins")
bookmarks Bookmark[]
sharedPosts Article[] @relation("shares")
sharedEvents Event[] @relation("shares")
seenBookings Registration[] @relation("seenBy")
// For full-text search
search Unsupported("tsvector") @default(dbgenerated("''::tsvector"))
claimedPromotions PromotionCode[]
formsWithMarkedCheckboxes Form[] @relation("formsWithMarkedCheckbox")
createdPages Page[]
@@unique([schoolServer, schoolUid])
@@index([search], type: Gin)
}
/// A bookmarked page, used to make personal quick access links
model Bookmark {
id String @id @default(dbgenerated("nanoid('bookmark:')"))
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
userId String
// The path to the bookmarked page. Up to the frontend's interpretation
path String
@@unique([userId, path])
}
/// Requests to become someone's godchild. Gets deleted once the request has been accepted (or denied). godchild is the requester, godparent is the requested.
model GodparentRequest {
id String @id @unique @default(dbgenerated("nanoid('godparentreq:')"))
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
godchild User @relation("godchild", fields: [godchildId], references: [id])
godchildId String
godparent User @relation("godparent", fields: [godparentId], references: [id])
godparentId String
@@unique([godchildId, godparentId])
}
/// UserCandidates are users in the registration process
model UserCandidate {
id String @id @default(dbgenerated("nanoid('candidate:')"))
token String @unique
createdAt DateTime @default(now())
email String @unique @db.VarChar(255)
emailValidated Boolean @default(false)
uid String @default("") @db.VarChar(255)
firstName String @default("") @db.VarChar(255)
lastName String @default("") @db.VarChar(255)
churrosPassword String @db.VarChar(255)
ldapPassword String @db.VarChar(255)
majorId String?
major Major? @relation(fields: [majorId], references: [id], onUpdate: Cascade, onDelete: Restrict)
graduationYear Int?
apprentice Boolean @default(false)
birthday DateTime?
cededImageRightsToTVn7 Boolean @default(false)
usingQuickSignup QuickSignup? @relation(fields: [quickSignupId], references: [id])
quickSignupId String?
}
/// A password reset token
model PasswordReset {
id String @id @default(dbgenerated("nanoid('passreset:')"))
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
userId String
expiresAt DateTime?
}
/// A email validation request
model EmailChange {
id String @id @default(dbgenerated("nanoid('emailchange:')"))
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
email String
expiresAt DateTime?
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
userId String
pending Boolean @default(true)
// token is not exposed to the API, whereas id has to be
token String @unique @default(dbgenerated("nanoid('', 30)"))
}
model QuickSignup {
id String @id @default(dbgenerated("nanoid('quicksignup:', 6)"))
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
validUntil DateTime
school School @relation(fields: [schoolId], references: [id], onDelete: Cascade, onUpdate: Cascade)
schoolId String
candidates UserCandidate[]
}
// Enum for the different kinds of logos
enum LogoSourceType {
InternalLink
ExternalLink
GroupLogo
Icon
}
/// A service
model Service {
id String @id @default(dbgenerated("nanoid('service:')"))
name String @db.VarChar(255)
url String @default("") @db.VarChar(255)
description String @default("") @db.VarChar(255)
logo String @db.VarChar(255)
logoSourceType LogoSourceType
schoolId String?
school School? @relation(fields: [schoolId], references: [id], onUpdate: Cascade, onDelete: SetNull)
studentAssociationId String?
studentAssociation StudentAssociation? @relation(fields: [studentAssociationId], references: [id], onUpdate: Cascade, onDelete: SetNull)
groupId String?
group Group? @relation(fields: [groupId], references: [id], onUpdate: Cascade, onDelete: SetNull)
importance Int @default(0)
hidden Boolean @default(false)
@@unique([schoolId, studentAssociationId, groupId, url])
@@unique([schoolId, studentAssociationId, groupId, name])
}
/// A single external link
model Link {
id String @id @default(dbgenerated("nanoid('link:')"))
name String @db.VarChar(255)
value String @db.VarChar(255)
createdAt DateTime @default(now())
// All resources that can have links
User User? @relation(fields: [userId], references: [id])
userId String?
StudentAssociation StudentAssociation? @relation(fields: [studentAssociationId], references: [id])
studentAssociationId String?
Group Group? @relation(fields: [groupId], references: [id])
groupId String?
Article Article? @relation(fields: [articleId], references: [id])
articleId String?
Event Event? @relation(fields: [eventId], references: [id])
eventId String?
Ticket Ticket? @relation(fields: [ticketId], references: [id])
ticketId String?
Notification Notification? @relation(fields: [notificationId], references: [id])
notificationId String?
Subject Subject? @relation(fields: [subjectId], references: [id])
subjectId String?
@@unique([name, userId, studentAssociationId, groupId, articleId, eventId, ticketId, notificationId, subjectId])
@@unique([userId, value])
@@unique([studentAssociationId, value])
@@unique([groupId, value])
@@unique([articleId, value])
@@unique([eventId, value])
@@unique([ticketId, value])
@@unique([notificationId, value])
@@unique([subjectId, value])
}
/// A school syllabus
model Major {
id String @id @default(dbgenerated("nanoid('major:')"))
uid String @unique @db.VarChar(255)
name String @db.VarChar(255)
shortName String @default("") @db.VarChar(255)
ldapSchoolUid String? @db.VarChar(255)
pictureFile String @default("") @db.VarChar(255)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
discontinued Boolean @default(false)
schools School[] @relation("MajorToSchool")
ldapSchool School? @relation("ldapSchool", fields: [ldapSchoolUid], references: [uid], onUpdate: Cascade, onDelete: SetNull)
students User[]
userCandidates UserCandidate[]
accessibleTickets Ticket[]
subjects Subject[]
minors Minor[]
}
model Minor {
id String @id @default(dbgenerated("nanoid('minor:')"))
name String
shortName String @default("")
slug String
majors Major[]
yearTier Int
subjects Subject[]
users User[]
@@unique([slug, yearTier])
}
model School {
id String @id @default(dbgenerated("nanoid('school:')"))
uid String @unique @db.VarChar(255)
name String @db.VarChar(255)
color String @db.VarChar(7)
studentMailDomain String @default("") @db.VarChar(255)
aliasMailDomains String[] @default([]) @db.VarChar(255)
description String @default("") @db.Text
address String @default("") @db.VarChar(255)
pictureFile String @default("") @db.VarChar(255)
majors Major[] @relation("MajorToSchool")
majorsLdapSchool Major[] @relation("ldapSchool")
studentAssociations StudentAssociation[]
accessibleTickets Ticket[]
contributionOptions ContributionOption[]
services Service[]
quickSignups QuickSignup[]
}
enum CredentialType {
Password
Token
GroupAccessToken
Google // External token, used for google sheets integration (and possibly more in the future)
}
/// A credential is a way to authenticate a user
model Credential {
id String @id @default(dbgenerated("nanoid('credential:')"))
userId String?
groupId String?
name String @default("") @db.VarChar(255)
type CredentialType
value String @db.VarChar(255)
userAgent String @default("") @db.VarChar(255)
createdAt DateTime @default(now())
expiresAt DateTime?
refresh String? @db.VarChar(255)
user User? @relation(fields: [userId], references: [id], onUpdate: Cascade, onDelete: Cascade)
group Group? @relation(fields: [groupId], references: [id], onUpdate: Cascade, onDelete: Cascade)
}
/// There is one student association per school
model StudentAssociation {
id String @id @default(dbgenerated("nanoid('ae:')"))
uid String @unique @db.VarChar(255)
description String @default("") @db.Text
schoolId String
name String @unique @db.VarChar(255)
links Link[]
pictureFile String @default("") @db.VarChar(255)
heroBackgroundFile String @default("") @db.VarChar(255) /// Used for the student association's homepage
allPrezMailingList String @default("") @db.VarChar(255)
allTrezMailingList String @default("") @db.VarChar(255)
allBoardMailingList String @default("") @db.VarChar(255)
internalMailDomain String @default("") @db.VarChar(255)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
school School @relation(fields: [schoolId], references: [id], onUpdate: Cascade, onDelete: Restrict)
groups Group[]
board Group? @relation("studentAssociationBoard", fields: [boardId], references: [id], onDelete: SetNull, onUpdate: Cascade)
boardId String? @unique
lydiaAccounts LydiaAccount[]
contributionOptions ContributionOption[]
services Service[]
admins User[] @relation("studentAssociationAdmins")
groupsEditors User[] @relation("studentAssociationGroupsEditor")
pages Page[]
}
model Contribution {
id String @id @default(dbgenerated("nanoid('contribution:')"))
option ContributionOption @relation(fields: [optionId], references: [id], onDelete: Cascade, onUpdate: Cascade)
optionId String
transaction LydiaTransaction?
transactionId String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
paid Boolean @default(false)
userId String
@@unique([optionId, userId])
}
model ContributionOption {
id String @id @default(dbgenerated("nanoid('contributionoption:')"))
offeredIn School @relation(fields: [offeredInId], references: [id], onDelete: Cascade, onUpdate: Cascade)
offeredInId String
paysFor StudentAssociation[]
beneficiary LydiaAccount? @relation(fields: [lydiaAccountId], references: [id], onDelete: SetNull, onUpdate: Cascade)
lydiaAccountId String?
name String
price Float
description String @default("") @db.Text
contributions Contribution[]
}
/// The different kinds of groups
enum GroupType {
StudentAssociationSection
Association
Club
List
Integration
Group
}
/// A group is a collection of users
model Group {
id String @id @default(dbgenerated("nanoid('g:')"))
uid String @unique @db.VarChar(255)
parentId String?
/// Helper field to get a whole tree without processing all groups
/// To be set to the group's id itself for root groups.
familyId String?
studentAssociationId String
pictureFile String @default("") @db.VarChar(255)
pictureFileDark String @default("") @db.VarChar(255)
name String @db.VarChar(255)
type GroupType
color String @db.VarChar(7)
selfJoinable Boolean @default(false)
roomIsOpen Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
unlisted Boolean @default(false)
address String @default("") @db.VarChar(255)
description String @default("") @db.VarChar(255)
email String @default("") @db.VarChar(255)
mailingList String @default("") @db.VarChar(255)
longDescription String @default("")
website String @default("") @db.VarChar(255)
ldapUid String @default("") @db.VarChar(255)
links Link[]
pages Page[]
/// Parent group, from which this group inherits its permissions
parent Group? @relation("parent", fields: [parentId], references: [id], onUpdate: Cascade, onDelete: Restrict)
children Group[] @relation("parent")
/// Family root, only created for performance reasons
familyRoot Group? @relation("root", fields: [familyId], references: [id], onUpdate: Cascade, onDelete: Restrict)
familyChildren Group[] @relation("root")
/// Related clubs
related Group[] @relation("related")
relatedTo Group[] @relation("related")
articles Article[]
members GroupMember[]
studentAssociation StudentAssociation @relation(fields: [studentAssociationId], references: [id], onUpdate: Cascade, onDelete: Restrict)
events Event[]
coOrganizedEvents Event[] @relation("coOrganizer")
lyiaAccounts LydiaAccount[]
tickets Ticket[] @relation("openTo")
services Service[]
restrictedFormSections FormSection[] @relation("restrictedTo")
notifications Notification[]
groupId String?
ticketGroupId String?
joinedByBookingTickets Ticket[] @relation("autojoin")
themes Theme[]
defaultApplicableOffers Promotion[] @relation("defaultApplicableOffers")
// For ldap
ldapGidNumber Int @unique @default(autoincrement())
// For full-text search
search Unsupported("tsvector") @default(dbgenerated("''::tsvector"))
forms Form[]
boardOf StudentAssociation? @relation("studentAssociationBoard")
boardOfId String?
tokens Credential[]
@@index([search], type: Gin)
}
/// The intermediate model between users
model GroupMember {
groupId String
memberId String
title String @default("") @db.VarChar(255)
president Boolean @default(false)
treasurer Boolean @default(false)
vicePresident Boolean @default(false)
secretary Boolean @default(false)
canEditMembers Boolean @default(false)
canEditArticles Boolean @default(false)
canScanEvents Boolean @default(false)
isDeveloper Boolean @default(false)
createdAt DateTime @default(now())
group Group @relation(fields: [groupId], references: [id], onUpdate: Cascade, onDelete: Cascade)
member User @relation(fields: [memberId], references: [id], onUpdate: Cascade, onDelete: Cascade)
@@id([groupId, memberId])
}
/// An article is a post in a group
model Article {
id String @id @default(dbgenerated("nanoid('a:')"))
authorId String?
groupId String
slug String @db.VarChar(255) // TODO remove
title String @db.VarChar(255)
body String @db.Text
published Boolean @default(false)
visibility Visibility @default(Private)
createdAt DateTime @default(now())
publishedAt DateTime @default(now())
notifiedAt DateTime? @default(now()) // to prevent old notifications before this was added. Another migration will remove this default value.
pictureFile String @default("") @db.VarChar(255)
links Link[]
comments Comment[]
author User? @relation(fields: [authorId], references: [id], onUpdate: Cascade, onDelete: SetNull)
group Group @relation(fields: [groupId], references: [id], onUpdate: Cascade, onDelete: Cascade)
event Event? @relation(fields: [eventId], references: [id])
eventId String?
reactions Reaction[]
sharedBy User[] @relation("shares")
// For full-text search
search Unsupported("tsvector") @default(dbgenerated("''::tsvector"))
@@index([search], type: Gin)
}
enum EventFrequency {
Once
Weekly
Monthly
Biweekly
}
/// An event is a date, time and place, as well as an optional ticket
model Event {
id String @id @default(dbgenerated("nanoid('e:')"))
createdAt DateTime @default(now())
updatedAt DateTime @default(now()) @updatedAt
authorId String?
groupId String
contactMail String
beneficiary LydiaAccount? @relation(fields: [lydiaAccountId], references: [id])
description String @db.Text
slug String @db.VarChar(255)
title String @db.VarChar(255)
// events without dates are useful when they're "drafts", but they' can't appear in the calendar - thus they're only visible by link
startsAt DateTime?
endsAt DateTime?
globalCapacity Int?
notifiedAt DateTime? @default(now()) // to prevent old notifications before this was added. Another migration will remove this default value.
location String @default("") @db.VarChar(255)
visibility Visibility
frequency EventFrequency @default(Once)
recurringUntil DateTime?
pictureFile String @default("") @db.VarChar(255)
showPlacesLeft Boolean @default(true)
managers EventManager[]
author User? @relation(fields: [authorId], references: [id], onUpdate: Cascade, onDelete: SetNull)
includeInKiosk Boolean @default(false)
group Group @relation(fields: [groupId], references: [id])
coOrganizers Group[] @relation("coOrganizer")
tickets Ticket[]
ticketGroups TicketGroup[]
articles Article[]
lydiaAccountId String?
links Link[]
bannedUsers User[] @relation("bannedFromEvents")
reactions Reaction[]
forms Form[]
sharedBy User[] @relation("shares")
applicableOffers Promotion[]
// For full-text search
search Unsupported("tsvector") @default(dbgenerated("''::tsvector"))
@@index([search], type: Gin)
}
enum Visibility {
Private
Unlisted
GroupRestricted
SchoolRestricted
Public
}
/// An event manager is a user that can scan tickets, and may be able to manage the event
model EventManager {
id String @id @default(dbgenerated("nanoid('em:')"))
eventId String
userId String
canVerifyRegistrations Boolean @default(true) // Can scan tickets
canEdit Boolean @default(false)
canEditPermissions Boolean @default(false)
event Event @relation(fields: [eventId], references: [id], onUpdate: Cascade, onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onUpdate: Cascade, onDelete: Cascade)
@@unique([eventId, userId])
}
/// A ticket group allows for conditions on multiple tickets, such as an upper limit on the sum of registrations in the sub-tickets
model TicketGroup {
id String @id @default(dbgenerated("nanoid('tg:')"))
eventId String
name String @db.VarChar(255)
capacity Int @default(0) // 0 means unlimited, capacity is on the sum of sub-tickets registrations
tickets Ticket[]
event Event @relation(fields: [eventId], references: [id])
@@unique([eventId, name])
}
/// Decide when to count a ticket as counting towards the capacity
enum TicketCountingPolicy {
OnBooked // Count when the ticket is booked
OnPaid // Count when the ticket is paid
}
/// A ticket is a way to register for an event. May include a price and conditions.
model Ticket {
id String @id @default(dbgenerated("nanoid('t:')"))
slug String
eventId String
ticketGroupId String?
name String @db.VarChar(255)
description String @db.VarChar(255)
opensAt DateTime?
closesAt DateTime?
minimumPrice Float
maximumPrice Float
capacity Int?
registrations Registration[]
links Link[]
allowedPaymentMethods PaymentMethod[] @default([]) // empty means all
countingPolicy TicketCountingPolicy @default(OnBooked)
// Conditions for that ticket.
openToPromotions Int[] @default([])
openToAlumni Boolean? @default(false) // false means only non-alumni, true means only alumni, null means both
openToExternal Boolean? @default(false) // same thing
openToContributors Boolean? // same thing
openToApprentices Boolean? // same thing
openToSchools School[]
openToMajors Major[]
openToGroups Group[] @relation("openTo")
godsonLimit Int @default(0) // 0 means unlimited
autojoinGroups Group[] @relation("autojoin")
onlyManagersCanProvide Boolean @default(false)
event Event @relation(fields: [eventId], references: [id], onUpdate: Cascade, onDelete: Cascade)
group TicketGroup? @relation(fields: [ticketGroupId], references: [id], onDelete: SetNull, onUpdate: Cascade)
Promotion Promotion? @relation(fields: [promotionId], references: [id])
promotionId String?
}
/// A reservation is a user's registration for a ticket
model Registration {
id String @id @default(dbgenerated("nanoid('r:')"))
ticketId String
externalBeneficiary String?
internalBeneficiary User? @relation(fields: [internalBeneficiaryId], references: [id], onUpdate: Cascade, onDelete: SetNull, name: "beneficiaryOf")
internalBeneficiaryId String?
authorId String?
authorEmail String @default("")
verifiedById String?
opposedById String?
cancelledById String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
paymentMethod PaymentMethod?
paid Boolean @default(false)
wantsToPay Float?
lydiaTransaction LydiaTransaction?
paypalTransaction PaypalTransaction?
ticket Ticket @relation(fields: [ticketId], references: [id], onUpdate: Cascade, onDelete: Cascade)
author User? @relation(name: "author", fields: [authorId], references: [id], onUpdate: Cascade, onDelete: Cascade)
verifiedBy User? @relation(name: "verifiedBy", fields: [verifiedById], references: [id], onUpdate: Cascade, onDelete: SetNull)
verifiedAt DateTime?
opposedBy User? @relation(name: "opposedBy", fields: [opposedById], references: [id], onUpdate: Cascade, onDelete: SetNull)
opposedAt DateTime?
cancelledBy User? @relation(name: "cancelledBy", fields: [cancelledById], references: [id], onDelete: SetNull, onUpdate: Cascade)
cancelledAt DateTime?
seenBy User[] @relation(name: "seenBy")
formAnswer Answer?
search Unsupported("tsvector") @default(dbgenerated("''::tsvector"))
@@index([search], type: Gin)
}
enum PaymentMethod {
Lydia
PayPal
Card
Transfer
Check
Cash
External
Other
}
/// A log entry is a log of an action that happened on the website
model LogEntry {
id String @id @default(dbgenerated("nanoid('log:')"))
happenedAt DateTime @default(now())
userId String?
area String @db.VarChar(255) // billeterie, gestion clubs, etc. à typer, mais pas dans la DB (pour être plus flexible)
action String @db.VarChar(255)
target String? @db.VarChar(255)
message String @db.Text
user User? @relation(fields: [userId], references: [id], onUpdate: Cascade, onDelete: SetNull)
}
/// A Lydia account
model LydiaAccount {
id String @id @default(dbgenerated("nanoid('lydia:')"))
groupId String?
group Group? @relation(fields: [groupId], references: [id], onUpdate: Cascade, onDelete: Cascade)
name String @default("") @db.VarChar(255)
privateToken String @default("") @db.VarChar(255)
vendorToken String @default("") @db.VarChar(255)
studentAssociationId String?
events Event[]
studentAssociation StudentAssociation? @relation(fields: [studentAssociationId], references: [id])
ContributionOption ContributionOption[]
@@unique([privateToken, vendorToken, groupId])
}
// Lydia payment
model LydiaTransaction {
id String @id @default(dbgenerated("nanoid('lydiapayment:')"))
phoneNumber String @default("") @db.VarChar(255)
registrationId String? @unique
registration Registration? @relation(fields: [registrationId], references: [id], onUpdate: Cascade, onDelete: Cascade)
shopPaymentId String? @unique
requestId String?
requestUuid String?
transactionId String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
contribution Contribution? @relation(fields: [studentAssociationContributionId], references: [id], onDelete: Cascade, onUpdate: Cascade)
studentAssociationContributionId String? @unique
paidCallback String?
}
enum PayPalTransactionStatus {
Created
Saved
Approved
Voided
Completed
PayerActionRequired
}
/// Paypal payment
model PaypalTransaction {
id String @id @default(dbgenerated("nanoid('paypalpayment:')"))
emailAddress String @default("") @db.VarChar(255)
registrationId String? @unique
registration Registration? @relation(fields: [registrationId], references: [id], onUpdate: Cascade, onDelete: Cascade)
status PayPalTransactionStatus?
/// PayPal's order ID.
orderId String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
/// A NotificationSubscription stores a user's subscription to push notifications on a user agent
model NotificationSubscription {
id String @id @default(dbgenerated("nanoid('notifsub:')"))
name String @default("") @db.VarChar(255)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade, onUpdate: Cascade)
ownerId String
endpoint String @unique
expiresAt DateTime?
authKey String
p256dhKey String
notifications Notification[]
}
/// A notification is a push notification that was sent to a user
model Notification {
id String @id @default(dbgenerated("nanoid('notif:')"))
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
timestamp DateTime?
subscription NotificationSubscription @relation(fields: [subscriptionId], references: [id], onDelete: Cascade, onUpdate: Cascade)
subscriptionId String
image String @default("")
actions Link[]
title String @db.VarChar(255)
imageFile String @default("")
body String @db.Text
vibrate Int[] @default([])
group Group? @relation(fields: [groupId], references: [id], onDelete: SetNull, onUpdate: Cascade)
groupId String?
channel NotificationChannel @default(Other)
user User? @relation(fields: [userId], references: [id], onDelete: SetNull, onUpdate: Cascade)
userId String?
goto String @default("")
}
/// A NotificationChannel represents the different kinds of reasons why you might receive a notification: a shotgun just opened, etc.
enum NotificationChannel {
Articles
Shotguns
Permissions
GroupBoard
GodparentRequests
Comments
Mandatory
Other // should't be used too much
}
/// Announcement is a way to get a message accross the entire site, such as for maintenance announcements.
model Announcement {
id String @id @default(dbgenerated("nanoid('ann:')"))
by User? @relation(fields: [userId], references: [id], onDelete: SetNull, onUpdate: Cascade)
userId String?
title String @db.VarChar(255)
body String @db.Text
warning Boolean
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
startsAt DateTime
endsAt DateTime
}
model TeachingUnit {
id String @id @default(dbgenerated("nanoid('ue:')"))
name String @db.VarChar(255)
shortName String @default("") @db.VarChar(255)
apogeeCode String? @db.VarChar(255)
subjects Subject[]
}
model Subject {
id String @id @default(dbgenerated("nanoid('subj:')"))
name String
slug String
shortName String @default("") @db.VarChar(255)
yearTier Int?
forApprentices Boolean @default(false)
links Link[]
apogeeCode String? @db.VarChar(255)
unitId String?
unit TeachingUnit? @relation(fields: [unitId], references: [id], onDelete: SetNull, onUpdate: Cascade)
nextExamAt DateTime?
majors Major[]
minors Minor[]
documents Document[]
// 1 for the first semester, 2 for the second one. Null means both
semester Int?
emoji String @default("") @db.VarChar(4)
@@unique([slug, yearTier, forApprentices])
}
enum DocumentType {
// Graded
Exam // Partiel
PracticalExam // BE
GradedExercises // DM
// Ungraded
Exercises // TD
Practical // TP
CourseNotes // CM
CourseSlides // Diapos
Summary // Fiche de rev, Fiche
Miscellaneous // Divers
}
model Document {
id String @id @default(dbgenerated("nanoid('doc:')"))
slug String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
schoolYear Int // stored using the school year start's year
title String
description String @db.Text
// Null subject means the document needs to be sorted
subject Subject? @relation(fields: [subjectId], references: [id], onDelete: Cascade, onUpdate: Cascade)
subjectId String?
type DocumentType
paperPaths String[] // le sujet
solutionPaths String[] // la correction
uploader User? @relation(fields: [uploaderId], references: [id], onDelete: Cascade, onUpdate: Cascade)
uploaderId String?
comments Comment[]
reactions Reaction[]
search Unsupported("tsvector") @default(dbgenerated("''::tsvector"))
@@unique([subjectId, slug])
@@index([search], type: Gin)
}
model Comment {
id String @id @default(dbgenerated("nanoid('comment:')"))
authorId String?
body String @db.Text
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
author User? @relation(fields: [authorId], references: [id], onDelete: Cascade, onUpdate: Cascade)
document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade, onUpdate: Cascade)
documentId String?
article Article? @relation(fields: [articleId], references: [id], onDelete: Cascade, onUpdate: Cascade)
articleId String?
inReplyTo Comment? @relation(name: "reply", fields: [inReplyToId], references: [id], onDelete: SetNull, onUpdate: Cascade)
inReplyToId String?
replies Comment[] @relation(name: "reply")
reactions Reaction[]
}
model Reaction {
id String @id @default(dbgenerated("nanoid('reac:')"))
emoji String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
author User? @relation(fields: [authorId], references: [id], onDelete: Cascade, onUpdate: Cascade)
authorId String?
document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade, onUpdate: Cascade)
documentId String?
article Article? @relation(fields: [articleId], references: [id], onDelete: Cascade, onUpdate: Cascade)
articleId String?
event Event? @relation(fields: [eventId], references: [id], onDelete: Cascade, onUpdate: Cascade)
eventId String?
comment Comment? @relation(fields: [commentId], references: [id], onDelete: Cascade, onUpdate: Cascade)
commentId String?
@@unique([emoji, authorId, documentId])
@@unique([emoji, authorId, articleId])
@@unique([emoji, authorId, eventId])
@@unique([emoji, authorId, commentId])
}
enum PromotionType {
SIMPPS
// More to come...
}
model PromotionCode {
id String @id @default(dbgenerated("nanoid('promocode:')"))
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
claimedAt DateTime?
code String @unique
claimedBy User? @relation(fields: [claimedById], references: [id])
claimedById String?
promotion Promotion @relation(fields: [promotionId], references: [id])
promotionId String
}
model Promotion {
id String @id @default(dbgenerated("nanoid('promo:')"))
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
validUntil DateTime?
type PromotionType
codes PromotionCode[]
validOn Ticket[]
validByDefaultOn Group[] @relation("defaultApplicableOffers")
priceOverride Int
events Event[]
}
model Form {
id String @id @default(dbgenerated("nanoid('form:')"))
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdBy User? @relation(fields: [createdById], references: [id], onDelete: SetNull, onUpdate: Cascade)
createdById String?
visibility Visibility
groupId String?
group Group? @relation(fields: [groupId], references: [id], onDelete: Cascade, onUpdate: Cascade)
event Event? @relation(fields: [eventId], references: [id], onDelete: SetNull, onUpdate: Cascade)
eventId String?
opensAt DateTime?
closesAt DateTime?
title String @db.VarChar(255)
description String @db.Text
sections FormSection[]