aboutsummaryrefslogtreecommitdiffstats
path: root/prisma/schema.prisma
blob: 1fbfc65c2aa312fe14a3c0153dbc86c04871ba2a (plain)
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
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider  = "postgresql"
  url       = env("POSTGRES_PRISMA_URL") // uses connection pooling
  directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
}

model Group {
  id           String        @id
  name         String
  currency     String        @default("$")
  participants Participant[]
  expenses     Expense[]
  createdAt    DateTime      @default(now())
}

model Participant {
  id              String           @id
  name            String
  group           Group            @relation(fields: [groupId], references: [id], onDelete: Cascade)
  groupId         String
  expensesPaidBy  Expense[]
  expensesPaidFor ExpensePaidFor[]
}

model Category {
  id       Int       @id @default(autoincrement())
  grouping String
  name     String
  Expense  Expense[]
}

model Expense {
  id              String           @id
  group           Group            @relation(fields: [groupId], references: [id], onDelete: Cascade)
  expenseDate     DateTime         @default(dbgenerated("CURRENT_DATE")) @db.Date
  title           String
  category        Category?        @relation(fields: [categoryId], references: [id])
  categoryId      Int              @default(0)
  amount          Int
  paidBy          Participant      @relation(fields: [paidById], references: [id], onDelete: Cascade)
  paidById        String
  paidFor         ExpensePaidFor[]
  groupId         String
  isReimbursement Boolean          @default(false)
  splitMode       SplitMode        @default(EVENLY)
  createdAt       DateTime         @default(now())
}

enum SplitMode {
  EVENLY
  BY_SHARES
  BY_PERCENTAGE
  BY_AMOUNT
}

model ExpensePaidFor {
  expense       Expense     @relation(fields: [expenseId], references: [id], onDelete: Cascade)
  participant   Participant @relation(fields: [participantId], references: [id], onDelete: Cascade)
  expenseId     String
  participantId String
  shares        Int         @default(1)

  @@id([expenseId, participantId])
}