aboutsummaryrefslogtreecommitdiff
path: root/prisma/schema.prisma
blob: 7c99fed157dc1d628ecc8fd956ab1fbd9b36576a (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
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
generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

// TODO: user deletion should delete all transactions
model User {
  id                   Int      @id @default(autoincrement())
  createdAt            DateTime @default(now())
  updatedAt            DateTime @updatedAt
  userName             String   @unique
  email                String   @unique
  fullName             String
  password             String
  refreshTokenVersion  Int @default(1)
  transactions         Transaction[]
  monthlyBudgetHistory MonthlyBudget[]
  friends              Friend[]
  friendOf             Friend[] @relation(name: "friend")
  collaboratorOf       TransactionCollaborator[]
}

model Transaction {
  id             Int      @id @default(autoincrement())
  user           User     @relation(fields: [userId], references: [id])
  userId         Int
  createdAt      DateTime @default(now())
  time           DateTime @default(now()) // can be edited from the client side
  type           TransactionType @default(SPENT)
  value          String
  currency       String
  reason         String
  place          String
  description    String
  collaborators  TransactionCollaborator[]
}

model TransactionCollaborator {
  id Int @id @default(autoincrement())
  transaction    Transaction @relation(fields: [transactionId], references: [id])
  transactionId  Int
  user           User     @relation(fields: [userId], references: [id])
  userId         Int
}

// each user has a unique monthly limit for each month
// the previous limit is set for the next month unless changed
// TODO: find a way to auto-generate a row for each user every month
// TODO: figure out a way to handle budgets with different currencies
// TODO: (maybe have only one primary currency and a budget for just that)
model MonthlyBudget {
  id          Int      @id @default(autoincrement())
  user        User     @relation(fields: [userId], references: [id])
  userId      Int
  createdAt   DateTime @default(now())

  month       Month
  year        Int
  value       Int
  currency    String
}

model Friend {
  id       Int  @id @default(autoincrement())
  user     User @relation(fields: [userId], references: [id])
  userId   Int
  friend   User @relation(name: "friend", fields: [friendId], references: [id])
  friendId Int

  @@unique([userId, friendId])
}

enum TransactionType {
  SPENT
  RECEIVED
  BORROWED
  LENT
}

enum Month {
  JANUARY
  FEBRUARY
  MARCH
  APRIL
  MAY
  JUNE
  JULY
  AUGUST
  SEPTEMBER
  OCTOBER
  NOVEMBER
  DECEMBER
}