-
Notifications
You must be signed in to change notification settings - Fork 47
/
schema.prisma
1071 lines (932 loc) · 40.1 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 client {
provider = "prisma-client-js"
binaryTargets = ["native"]
}
generator dbml {
provider = "prisma-dbml-generator"
output = "."
projectName = "Podkrepi.bg"
projectDatabaseType = "PostgreSQL"
outputName = "podkrepi.dbml"
}
generator nestjsDto {
provider = "prisma-generator-nestjs-dto"
output = "apps/api/src/domain/generated"
entityPrefix = ""
outputToNestJsResourceStructure = "true"
updateDtoPrefix = "Update"
entitySuffix = ""
createDtoPrefix = "Create"
dtoSuffix = "Dto"
reExport = "true"
exportRelationModifierClasses = "true"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
/// Generic person object
model Person {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
firstName String @map("first_name") @db.VarChar(100)
lastName String @map("last_name") @db.VarChar(100)
email String? @unique @db.Citext
phone String? @db.VarChar(50)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
// Receive marketing notifications
newsletter Boolean? @default(false)
helpUsImprove Boolean? @default(false) @map("help_us_improve")
address String? @db.VarChar(100)
birthday DateTime? @db.Timestamptz(6)
emailConfirmed Boolean? @default(false) @map("email_confirmed")
/// Uniform Civil Number (NCN, EGN)
/// https://en.wikipedia.org/wiki/National_identification_number#Bulgaria
personalNumber String? @unique @map("personal_number")
companyId String? @unique @map("company_id") @db.Uuid
keycloakId String? @unique @map("keycloak_id") @db.Uuid
stripeCustomerId String? @unique @map("stripe_customer_id")
picture String? @db.VarChar(250)
profileEnabled Boolean @default(true) @map("profile_enabled")
// Used to verify some emails sent to the user
benefactors Benefactor[]
beneficiaries Beneficiary[]
campaignFiles CampaignFile[]
campaigns Campaign[]
coordinators Coordinator?
documents Document[]
donationWish DonationWish[]
Donation Donation[]
expenses Expense[]
infoRequests InfoRequest[]
irregularities Irregularity[]
irregularityFiles IrregularityFile[]
expenseFiles ExpenseFile[]
organizer Organizer?
recurringDonations RecurringDonation[]
supporters Supporter[]
transfers Transfer[]
withdrawals Withdrawal[]
publishedNews CampaignNews[]
newsFiles CampaignNewsFile[]
company Company? @relation(fields: [companyId], references: [id])
@@index([keycloakId], map: "keycloak_id_idx")
@@index([stripeCustomerId], map: "stripe_customer_id_idx")
@@map("people")
}
model Company {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
companyName String @map("company_name") @db.VarChar(100)
/// BULSTAT Unified Identification Code (UIC)
/// https://psc.egov.bg/en/psc-starting-a-business-bulstat
companyNumber String @unique
legalPersonName String? @map("legal_person_name")
countryCode String? @map("country_code") @db.Citext
cityId String? @map("city_id") @db.Uuid
personId String? @unique @map("person_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
beneficiaries Beneficiary[]
Campaign Campaign[]
person Person?
affiliate Affiliate?
@@map("companies")
}
model Affiliate {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
status AffiliateStatus @default(pending)
affiliateCode String? @unique @map("affiliate_code")
companyId String @unique @map("company_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
company Company @relation(fields: [companyId], references: [id])
payments Payment[]
@@map("affiliates")
}
/// Organizer is the person who manages the campaign on behalf of the Beneficiary
model Organizer {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
personId String @unique @map("person_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
person Person @relation(fields: [personId], references: [id])
beneficiaries Beneficiary[]
campaigns Campaign[]
campaignApplication CampaignApplication[]
@@map("organizers")
}
/// Coordinator is the person who manages the campaign on behalf of Podkrepi.bg
model Coordinator {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
personId String @unique @map("person_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
person Person @relation(fields: [personId], references: [id])
beneficiaries Beneficiary[]
campaigns Campaign[]
@@map("coordinators")
}
/// Benefactor is the person who gives money
model Benefactor {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
personId String @map("person_id") @db.Uuid
/// Payment provider customer id
extCustomerId String? @unique @map("ext_customer_id") @db.VarChar(50)
///
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
person Person @relation(fields: [personId], references: [id])
@@map("benefactors")
}
/// Beneficiary is the person who receives the benefit
model Beneficiary {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
type BeneficiaryType
/// Person in need when type is `individual`
personId String? @map("person_id") @db.Uuid
coordinatorId String? @map("coordinator_id") @db.Uuid
countryCode String @map("country_code") @db.Citext
cityId String @map("city_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
coordinatorRelation PersonRelation? @default(none) @map("coordinator_relation")
description String?
privateData Json? @map("private_data")
publicData Json? @map("public_data")
/// Company in need when type is `company`
companyId String? @map("company_id") @db.Uuid
/// Organizer for this beneficiary
organizerId String? @map("organizer_id") @db.Uuid
organizerRelation PersonRelation? @default(none) @map("organizer_relation")
city City @relation(fields: [cityId], references: [id])
company Company? @relation(fields: [companyId], references: [id])
coordinator Coordinator? @relation(fields: [coordinatorId], references: [id])
organizer Organizer? @relation(fields: [organizerId], references: [id])
person Person? @relation(fields: [personId], references: [id])
campaigns Campaign[]
@@map("beneficiaries")
}
model CampaignType {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String @db.VarChar(50)
slug String @unique @db.VarChar(50)
description String? @db.VarChar(200)
parentId String? @map("parent_id") @db.Uuid
category CampaignTypeCategory @default(others)
parent CampaignType? @relation("ParentCategory", fields: [parentId], references: [id])
children CampaignType[] @relation("ParentCategory")
campaigns Campaign[]
@@map("campaign_types")
}
model Campaign {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
state CampaignState @default(draft)
slug String @unique @db.VarChar(250)
title String @db.VarChar(200)
essence String @db.VarChar(500)
coordinatorId String @map("coordinator_id") @db.Uuid
beneficiaryId String @map("beneficiary_id") @db.Uuid
campaignTypeId String @map("campaign_type_id") @db.Uuid
description String?
targetAmount Int? @default(0) @map("target_amount")
startDate DateTime? @map("start_date") @db.Timestamptz(6)
endDate DateTime? @map("end_date") @db.Timestamptz(6)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
approvedById String? @map("approved_by_id") @db.Uuid
currency Currency @default(BGN)
allowDonationOnComplete Boolean @default(false) @map("allow_donation_on_complete")
paymentReference String @unique @map("payment_reference") @db.VarChar(15)
organizerId String? @map("organizer_id") @db.Uuid
companyId String? @map("company_id") @db.Uuid
approvedBy Person? @relation(fields: [approvedById], references: [id])
beneficiary Beneficiary @relation(fields: [beneficiaryId], references: [id])
campaignType CampaignType @relation(fields: [campaignTypeId], references: [id], onDelete: Cascade, onUpdate: NoAction)
coordinator Coordinator @relation(fields: [coordinatorId], references: [id])
organizer Organizer? @relation(fields: [organizerId], references: [id])
company Company? @relation(fields: [companyId], references: [id])
campaignFiles CampaignFile[]
donationWish DonationWish[]
irregularities Irregularity[]
outgoingTransfers Transfer[] @relation("source_campaign")
incomingTransfers Transfer[] @relation("target_campaign")
vaults Vault[]
withdrawals Withdrawal[]
slugArchive SlugArchive[]
campaignNews CampaignNews[]
notificationLists NotificationList[]
@@map("campaigns")
}
model CampaignNews {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
campaignId String @map("campaign_id") @db.Uuid
publisherId String @map("publisher_id") @db.Uuid
slug String @unique @db.VarChar(250)
title String
author String
sourceLink String? @map("source_link")
state CampaignNewsState @default(draft)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
publishedAt DateTime? @map("published_at") @db.Timestamptz(6)
editedAt DateTime? @map("edited_at") @db.Timestamptz(6)
description String
campaign Campaign @relation(fields: [campaignId], references: [id])
publisher Person @relation(fields: [publisherId], references: [id])
newsFiles CampaignNewsFile[]
@@map("campaign_news")
}
model NotificationList {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
campaignId String @map("campaign_id") @db.Uuid
name String?
campaign Campaign @relation(fields: [campaignId], references: [id])
@@map("notification_list")
}
// Stores the template id's on the marketing platform
model MarketingTemplates {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String?
@@map("marketing_templates")
}
// Stores marketing notifications consents for non-registered emails
model UnregisteredNotificationConsent {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
email String @unique @db.Citext
consent Boolean @default(false)
@@map("unregistered_notification_consent")
}
// Keeps track of some email types being send
model EmailSentRegistry {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
email String @db.Citext
dateSent DateTime @map("date_sent") @db.Timestamptz(6)
campaignId String? @map("campaign_id") @db.Uuid
type EmailType
@@map("email_sent_registry")
}
/// Keeps track of previous slugs that are not used currently in any active campaign
model SlugArchive {
slug String @id @unique @db.VarChar(250)
/// Stores the id of the last campaign that has used it
campaignId String @map("campaign_id") @db.Uuid
campaign Campaign @relation(fields: [campaignId], references: [id])
@@map("slug_archive")
}
model Irregularity {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
campaignId String @map("campaign_id") @db.Uuid
personId String @map("person_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
status IrregularityStatus @default(initial)
reason IrregularityReason @default(other)
description String
notifierType NotifierType @default(other)
campaign Campaign @relation(fields: [campaignId], references: [id])
person Person @relation(fields: [personId], references: [id])
files IrregularityFile[]
@@map("irregularities")
}
model CampaignFile {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
filename String @db.VarChar(200)
campaignId String @map("campaign_id") @db.Uuid
personId String @map("person_id") @db.Uuid
mimetype String @db.VarChar(100)
role CampaignFileRole
campaign Campaign @relation(fields: [campaignId], references: [id])
person Person @relation(fields: [personId], references: [id])
@@map("campaign_files")
}
model CampaignNewsFile {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
filename String @db.VarChar(200)
newsId String @map("news_id") @db.Uuid
personId String @map("person_id") @db.Uuid
mimetype String @db.VarChar(100)
role CampaignFileRole
news CampaignNews @relation(fields: [newsId], references: [id], onDelete: Cascade)
person Person @relation(fields: [personId], references: [id])
@@map("campaign_news_files")
}
model IrregularityFile {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
filename String @db.VarChar(200)
mimetype String @db.VarChar(100)
irregularityId String @map("irregularity_id") @db.Uuid
uploaderId String @map("uploader_id") @db.Uuid
irregularity Irregularity @relation(fields: [irregularityId], references: [id])
uploadedBy Person @relation(fields: [uploaderId], references: [id])
@@map("irregularity_files")
}
model InfoRequest {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
personId String @map("person_id") @db.Uuid
message String
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
person Person @relation(fields: [personId], references: [id])
@@map("info_requests")
}
model Supporter {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
personId String @map("person_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
deletedAt DateTime? @map("deleted_at") @db.Timestamptz(6)
comment String? @db.VarChar(500)
associationMember Boolean @default(false) @map("association_member")
benefactorCampaign Boolean @default(false) @map("benefactor_campaign")
benefactorPlatform Boolean @default(false) @map("benefactor_platform")
companyOtherText String? @map("company_other_text") @db.VarChar(100)
companySponsor Boolean @default(false) @map("company_sponsor")
companyVolunteer Boolean @default(false) @map("company_volunteer")
partnerBussiness Boolean @default(false) @map("partner_bussiness")
partnerNpo Boolean @default(false) @map("partner_npo")
partnerOtherText String? @map("partner_other_text") @db.VarChar(100)
roleAssociationMember Boolean @default(false) @map("role_association_member")
roleBenefactor Boolean @default(false) @map("role_benefactor")
roleCompany Boolean @default(false) @map("role_company")
rolePartner Boolean @default(false) @map("role_partner")
roleVolunteer Boolean @default(false) @map("role_volunteer")
volunteerBackend Boolean @default(false) @map("volunteer_backend")
volunteerDesigner Boolean @default(false) @map("volunteer_designer")
volunteerDevOps Boolean @default(false) @map("volunteer_dev_ops")
volunteerFinancesAndAccounts Boolean @default(false) @map("volunteer_finances_and_accounts")
volunteerFrontend Boolean @default(false) @map("volunteer_frontend")
volunteerLawyer Boolean @default(false) @map("volunteer_lawyer")
volunteerMarketing Boolean @default(false) @map("volunteer_marketing")
volunteerProjectManager Boolean @default(false) @map("volunteer_project_manager")
volunteerQa Boolean @default(false) @map("volunteer_qa")
volunteerSecurity Boolean @default(false) @map("volunteer_security")
person Person @relation(fields: [personId], references: [id])
@@map("supporters")
}
model City {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String @db.VarChar(100)
postalCode String @unique @map("postal_code")
countryId String @map("country_id") @db.Uuid
countryCode Country @relation(fields: [countryId], references: [id])
beneficiaries Beneficiary[]
@@map("cities")
}
model Country {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String @db.VarChar(100)
countryCode String @unique @map("country_code") @db.Citext
cities City[]
@@map("countries")
}
model Vault {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
currency Currency @default(BGN)
amount Int @default(0)
campaignId String @map("campaign_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
name String @default("") @db.VarChar(100)
blockedAmount Int @default(0)
campaign Campaign @relation(fields: [campaignId], references: [id])
donations Donation[]
expenses Expense[]
recurringDonations RecurringDonation[]
sourceTransfers Transfer[] @relation("source_vault")
targetTransfers Transfer[] @relation("target_vault")
withdraws Withdrawal[]
@@map("vaults")
}
model Payment {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
extCustomerId String @map("ext_customer_id") @db.VarChar(50)
extPaymentIntentId String @unique @map("ext_payment_intent_id")
extPaymentMethodId String @map("ext_payment_method_id")
type PaymentType
currency Currency @default(BGN)
status PaymentStatus @default(initial)
provider PaymentProvider @default(none)
affiliateId String? @map("affiliate_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
chargedAmount Int @default(0) @map("charged_amount")
amount Int @default(0)
billingEmail String? @map("billing_email") @db.VarChar
billingName String? @map("billing_name") @db.VarChar
affiliate Affiliate? @relation(fields: [affiliateId], references: [id])
donations Donation[]
@@map("payments")
}
model Donation {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
paymentId String @map("payment_id") @db.Uuid
type DonationType @default(donation)
/// Vault where the funds are going
targetVaultId String @map("target_vault_id") @db.Uuid
amount Int @default(0)
personId String? @map("person_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
person Person? @relation(fields: [personId], references: [id])
targetVault Vault @relation(fields: [targetVaultId], references: [id])
DonationWish DonationWish?
metadata DonationMetadata?
payment Payment @relation(fields: [paymentId], references: [id])
@@map("donations")
}
model DonationMetadata {
donationId String @id @unique @map("donation_id") @db.Uuid
name String? @db.VarChar
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
extraData Json? @map("extra_data")
donation Donation @relation(fields: [donationId], references: [id])
@@map("donation_metadata")
}
model DonationWish {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
message String
campaignId String @map("campaign_id") @db.Uuid
personId String? @map("person_id") @db.Uuid
donationId String? @unique @map("donation_id") @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
campaign Campaign @relation(fields: [campaignId], references: [id])
person Person? @relation(fields: [personId], references: [id])
donation Donation? @relation(fields: [donationId], references: [id])
@@map("donation_wishes")
}
/// Donate on monthly basis
model RecurringDonation {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
status RecurringDonationStatus
vaultId String @map("vault_id") @db.Uuid
personId String @map("person_id") @db.Uuid
/// Payment provider Subscription id
extSubscriptionId String @map("ext_subscription_id") @db.VarChar(50)
extCustomerId String? @map("ext_customer_id") @db.VarChar(50)
///
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
amount Int @default(0)
currency Currency @default(BGN)
person Person @relation(fields: [personId], references: [id])
sourceVault Vault @relation(fields: [vaultId], references: [id])
@@map("recurring_donations")
}
/// Move funds from one vault to another
model Transfer {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
status TransferStatus @default(initial)
currency Currency
amount Int @default(0)
reason String @db.VarChar(100)
/// Source vault
sourceVaultId String @map("source_vault_id") @db.Uuid
sourceCampaignId String @map("source_campaign_id") @db.Uuid
/// Destination vault
targetVaultId String @map("target_vault_id") @db.Uuid
targetCampaignId String @map("target_campaign_id") @db.Uuid
approvedById String? @map("approved_by_id") @db.Uuid
documentId String? @map("document_id") @db.Uuid
targetDate DateTime? @default(now()) @map("target_date")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
approvedBy Person? @relation(fields: [approvedById], references: [id])
sourceCampaign Campaign @relation("source_campaign", fields: [sourceCampaignId], references: [id])
sourceVault Vault @relation("source_vault", fields: [sourceVaultId], references: [id])
targetCampaign Campaign @relation("target_campaign", fields: [targetCampaignId], references: [id])
targetVault Vault @relation("target_vault", fields: [targetVaultId], references: [id])
@@map("transfers")
}
/// Remove funds from a vault to given bank account
model Withdrawal {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
status WithdrawStatus @default(initial)
currency Currency
amount Int @default(0)
reason String @db.VarChar(100)
/// Source vault
sourceVaultId String @map("source_vault_id") @db.Uuid
sourceCampaignId String @map("source_campaign_id") @db.Uuid
/// Destination bank account
bankAccountId String @map("bank_account_id") @db.Uuid
documentId String? @map("document_id") @db.Uuid
approvedById String? @map("approved_by_id") @db.Uuid
targetDate DateTime? @default(now()) @map("target_date")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
approvedBy Person? @relation(fields: [approvedById], references: [id])
bankAccount BankAccount @relation(fields: [bankAccountId], references: [id])
sourceCampaign Campaign @relation(fields: [sourceCampaignId], references: [id])
sourceVault Vault @relation(fields: [sourceVaultId], references: [id])
@@map("withdrawals")
}
model BankAccount {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
status BankAccountStatus @default(new)
/// IBAN number
ibanNumber String @db.VarChar(34)
/// Name of account holder
accountHolderName String @map("account_holder_name")
/// Company or individual
accountHolderType AccountHolderType @map("account_holder_type")
/// Bank name
bankName String? @map("bank_name") @db.VarChar(50)
/// Bank Identification Code, BIC/SWIFT code
bankIdCode String? @map("bank_id_code") @db.VarChar(50)
fingerprint String? @db.VarChar(100)
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
withdraws Withdrawal[]
@@map("bank_accounts")
}
// Stores all movements for Podkrepi.bg IBAN
model BankTransaction {
id String @id @unique @db.VarChar(250)
/// IBAN number of the account tracked
ibanNumber String @map("iban_number") @db.VarChar(34)
/// Bank name
bankName String @map("bank_name") @db.VarChar(50)
/// Bank Identification Code, BIC/SWIFT code
bankIdCode String @map("bank_id_code") @db.VarChar(50)
transactionDate DateTime @map("transaction_date") @db.Timestamptz(6)
senderName String? @map("sender_name") @db.VarChar(100)
recipientName String? @map("recipient_name") @db.VarChar(100)
senderIban String? @map("sender_iban") @db.VarChar(34)
recipientIban String? @map("recipient_iban") @db.VarChar(34)
amount Float @default(0)
currency Currency @default(BGN)
description String @db.Text
//Matched campaign payment code
matchedRef String? @map("matched_ref") @db.VarChar(100)
type BankTransactionType
// For Bank donations, describes if campaign was recognized and donation imported
bankDonationStatus BankDonationStatus?
// If a notification was sent about the failed status of the donation
notified Boolean? @default(false)
@@map("bank_transactions")
}
/// Pay for something from a given vault
model Expense {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
type ExpenseType
description String?
vaultId String @map("vault_id") @db.Uuid
documentId String? @map("document_id") @db.Uuid
approvedById String? @db.Uuid
amount Int @default(0)
currency Currency @default(BGN)
status ExpenseStatus
deleted Boolean @default(false)
approvedBy Person? @relation(fields: [approvedById], references: [id])
document Document? @relation(fields: [documentId], references: [id])
vault Vault @relation(fields: [vaultId], references: [id])
spentAt DateTime @default(now()) @map("spent_at") @db.Timestamptz(6)
expenseFiles ExpenseFile[]
@@map("expenses")
}
model ExpenseFile {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
filename String @db.VarChar(200)
mimetype String @db.VarChar(100)
expenseId String @map("expense_id") @db.Uuid
uploaderId String @map("uploader_id") @db.Uuid
expense Expense @relation(fields: [expenseId], references: [id])
uploadedBy Person @relation(fields: [uploaderId], references: [id])
@@map("expense_files")
}
model Document {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
type DocumentType
name String @db.VarChar(100)
filename String @db.VarChar(100)
filetype String? @db.VarChar(3)
description String? @db.VarChar(200)
/// Data storage source url
sourceUrl String @map("source_url")
/// Person who uploaded the document
ownerId String @map("owner_id") @db.Uuid
owner Person @relation(fields: [ownerId], references: [id])
expenses Expense[]
@@map("documents")
}
model BankTransactionsFile {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
filename String @db.VarChar(200)
mimetype String @db.VarChar(50)
bankTransactionsFileId String @map("bank_transactions_file_id") @db.VarChar(50)
type BankTransactionsFileType @default(xml)
personId String @map("person_id") @db.Uuid
@@map("bank_transactions_files")
}
enum BeneficiaryType {
individual
company
@@map("beneficiary_type")
}
/// https://developers.google.com/people/api/rest/v1/people?hl=pt#relation
enum PersonRelation {
none
parent
spouse
child
mother
father
brother
sister
friend
relative
partner
domesticPartner
manager
assistant
colleague
myself
myorg
@@map("person_relation")
}
enum CampaignState {
initial
draft
pending_validation
approved
rejected
active
active_pending_validation
suspended
complete
disabled
error
deleted
@@map("campaign_state")
}
enum CampaignNewsState {
draft
published
@@map("campaign_news_state")
}
enum Currency {
BGN
EUR
USD
@@map("currency")
}
enum ExpenseStatus {
pending
approved
canceled
}
enum ExpenseType {
none
internal
operating
administrative
medical
services
groceries
transport
accommodation
shipping
utility
rental
legal
bank
advertising
other
@@map("expense_type")
}
enum PaymentProvider {
none
stripe
paypal
epay
bank
cash
@@map("payment_provider")
}
enum DocumentType {
invoice
receipt
medical_record
other
@@map("document_type")
}
enum DonationType {
donation
corporate
@@map("donation_type")
}
enum PaymentType {
single
category
benevity
@@map("payment_type")
}
enum PaymentStatus {
initial
invalid
incomplete
declined
waiting
cancelled
guaranteed
succeeded
deleted
refund
paymentRequested
@@map("payment_status")
}
enum RecurringDonationStatus {
trialing
active
canceled
incomplete
incompleteExpired
pastDue
unpaid
@@map("recurring_donation_status")
}
enum WithdrawStatus {
initial
invalid
incomplete
declined
cancelled
succeeded
@@map("withdraw_status")
}
enum TransferStatus {
initial
invalid
incomplete
declined
cancelled
succeeded
@@map("transfer_status")
}
enum AccountHolderType {
individual
company
@@map("account_holder_type")
}
/// For bank accounts, possible values are `new`, `validated`, `verified`, `verification_failed`, or `errored`.
/// A bank account that hasn’t had any activity or validation performed is `new`. If Stripe can determine
/// that the bank account exists, its status will be `validated`. Note that there often isn’t enough
/// information to know (e.g., for smaller credit unions), and the validation is not always run.
/// If customer bank account verification has succeeded, the bank account status will be `verified`.
/// If the verification failed for any reason, such as microdeposit failure, the status will be
/// `verification_failed`. If a transfer sent to this bank account fails, we’ll set the status to `errored`
/// and will not continue to send transfers until the bank details are updated.
/// For external accounts, possible values are `new` and `errored`. Validations aren’t run against external
/// accounts because they’re only used for payouts. This means the other statuses don’t apply. If a
/// transfer fails, the status is set to errored and transfers are stopped until account details are updated.
/// https://stripe.com/docs/api/customer_bank_accounts/object#customer_bank_account_object-status
enum BankAccountStatus {
new
validated
verified
verification_failed
errored
@@map("bank_account_status")
}
enum BankTransactionType {
debit
credit
@@map("bank_transaction_type")
}
enum BankDonationStatus {
unrecognized
imported
incomplete
reImported @map("re_imported")
importFailed @map("import_failed")
@@map("bank_donation_status")
}
enum CampaignTypeCategory {
medical
charity
disasters
education
events
environment
sport
art
nature
animals
others
@@map("campaign_type_category")
}
enum AffiliateStatus {
active
pending
cancelled
rejected
}
enum CampaignFileRole {
background
coordinator
campaignPhoto
invoice
document
profilePhoto
campaignListPhoto
beneficiaryPhoto
organizerPhoto
gallery
@@map("campaign_file_role")
}
enum IrregularityStatus {
initial
confirmed
declined
@@map("irregularity_status")
}
enum IrregularityReason {
duplicate
inappropriate
illegalActivity
misinformation
privacyViolation
spam
irrelevant
political
discrimination
explicitContent
fraud
other
@@map("irregularity_reason")
}
enum NotifierType {
benefactor
other
@@map("notifier_type")
}
enum BankTransactionsFileType {
xml
other
@@map("bank_transactions_file_type")
}
enum EmailType {
confirmConsent