-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathschema.prisma
More file actions
293 lines (258 loc) · 8.92 KB
/
Copy pathschema.prisma
File metadata and controls
293 lines (258 loc) · 8.92 KB
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
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("SUPABASE_DATABASE_URL")
directUrl = env("DIRECT_URL")
}
enum GroupRole {
OWNER
MEMBER
}
enum ActivityType {
expense_created
expense_updated
expense_deleted
settlement_created
settlement_reminder
member_joined
member_invited
}
enum PaymentStatus {
pending
succeeded
failed
}
model User {
id String @id @default(uuid())
email String @unique
passwordHash String
name String
avatarUrl String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
memberships GroupMember[]
createdGroups Group[] @relation("group_creator")
expenses Expense[] @relation("expense_payer")
recurringExpensesPaid RecurringExpense[] @relation("recurring_expense_payer")
recurringExpensesCreated RecurringExpense[] @relation("recurring_expense_creator")
splits Split[]
recurringExpenseSplits RecurringExpenseSplit[]
settlementsPaid Settlement[] @relation("settlement_payer")
settlementsReceived Settlement[] @relation("settlement_receiver")
balances Balance[] @relation("balance_user")
counterpartyBalances Balance[] @relation("balance_counterparty")
refreshTokens RefreshToken[]
activities Activity[]
pushTokens PushToken[]
paymentsSent Payment[] @relation("payment_payer")
paymentsReceived Payment[] @relation("payment_receiver")
@@map("users")
}
model Group {
id String @id @default(uuid())
name String
createdBy String
currency String
defaultSplitType String?
defaultSplitConfig String?
shareToken String? @unique
shareEnabled Boolean @default(false)
createdAt DateTime @default(now())
deletedAt DateTime?
creator User @relation("group_creator", fields: [createdBy], references: [id])
members GroupMember[]
expenses Expense[]
recurringExpenses RecurringExpense[]
balances Balance[]
settlements Settlement[]
activities Activity[]
payments Payment[]
invites GroupInvite[]
@@index([createdBy])
@@index([shareToken])
@@map("groups")
}
model GroupMember {
id String @id @default(uuid())
groupId String
userId String
role GroupRole @default(MEMBER)
joinedAt DateTime @default(now())
group Group @relation(fields: [groupId], references: [id])
user User @relation(fields: [userId], references: [id])
@@unique([groupId, userId])
@@index([groupId])
@@index([userId])
@@map("group_members")
}
model Expense {
id String @id @default(uuid())
groupId String
payerId String
description String
totalAmountCents BigInt
currency String
category String?
idempotencyKey String? @unique
createdAt DateTime @default(now())
group Group @relation(fields: [groupId], references: [id])
payer User @relation("expense_payer", fields: [payerId], references: [id])
splits Split[]
receipt Receipt?
@@index([groupId])
@@index([payerId])
@@index([createdAt])
@@index([groupId, createdAt])
@@map("expenses")
}
model RecurringExpense {
id String @id @default(uuid())
groupId String
payerId String
createdBy String
description String
totalAmountCents BigInt
currency String
category String?
frequency String
nextOccurrenceAt DateTime
lastGeneratedAt DateTime?
active Boolean @default(true)
createdAt DateTime @default(now())
group Group @relation(fields: [groupId], references: [id])
payer User @relation("recurring_expense_payer", fields: [payerId], references: [id])
creator User @relation("recurring_expense_creator", fields: [createdBy], references: [id])
splits RecurringExpenseSplit[]
@@index([groupId])
@@index([payerId])
@@index([createdBy])
@@index([active, nextOccurrenceAt])
@@index([groupId, active])
@@map("recurring_expenses")
}
model Split {
id String @id @default(uuid())
expenseId String
userId String
owedAmountCents BigInt
paidAmountCents BigInt
expense Expense @relation(fields: [expenseId], references: [id])
user User @relation(fields: [userId], references: [id])
@@index([expenseId])
@@map("splits")
}
model RecurringExpenseSplit {
id String @id @default(uuid())
recurringExpenseId String
userId String
owedAmountCents BigInt
paidAmountCents BigInt
recurringExpense RecurringExpense @relation(fields: [recurringExpenseId], references: [id])
user User @relation(fields: [userId], references: [id])
@@index([recurringExpenseId])
@@map("recurring_expense_splits")
}
model Balance {
id String @id @default(uuid())
groupId String
userId String
counterpartyUserId String
amountCents BigInt
group Group @relation(fields: [groupId], references: [id])
user User @relation("balance_user", fields: [userId], references: [id])
counterpartyUser User @relation("balance_counterparty", fields: [counterpartyUserId], references: [id])
@@unique([groupId, userId, counterpartyUserId])
@@index([groupId])
@@index([userId])
@@map("balances")
}
model Settlement {
id String @id @default(uuid())
groupId String
payerId String
receiverId String
amountCents BigInt
idempotencyKey String? @unique
createdAt DateTime @default(now())
group Group @relation(fields: [groupId], references: [id])
payer User @relation("settlement_payer", fields: [payerId], references: [id])
receiver User @relation("settlement_receiver", fields: [receiverId], references: [id])
@@index([groupId])
@@map("settlements")
}
model Receipt {
id String @id @default(uuid())
expenseId String @unique
fileKey String
createdAt DateTime @default(now())
expense Expense @relation(fields: [expenseId], references: [id])
@@map("receipts")
}
model RefreshToken {
id String @id @default(uuid())
userId String
tokenHash String
expiresAt DateTime
revokedAt DateTime?
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id])
@@index([userId])
@@map("refresh_tokens")
}
model Activity {
id String @id @default(uuid())
groupId String
actorUserId String
type ActivityType
entityId String
metadata Json
createdAt DateTime @default(now())
group Group @relation(fields: [groupId], references: [id])
actor User @relation(fields: [actorUserId], references: [id])
@@index([groupId])
@@index([createdAt])
@@index([groupId, createdAt])
@@map("activities")
}
model GroupInvite {
id String @id @default(uuid())
groupId String
email String
role GroupRole @default(MEMBER)
invitedBy String
createdAt DateTime @default(now())
group Group @relation(fields: [groupId], references: [id])
@@unique([groupId, email])
@@index([email])
@@map("group_invites")
}
model PushToken {
id String @id @default(uuid())
userId String
token String @unique
deviceType String
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id])
@@index([userId])
@@map("push_tokens")
}
model Payment {
id String @id @default(uuid())
groupId String
payerId String
receiverId String
amountCents BigInt
stripePaymentIntentId String @unique
idempotencyKey String? @unique
status PaymentStatus @default(pending)
createdAt DateTime @default(now())
group Group @relation(fields: [groupId], references: [id])
payer User @relation("payment_payer", fields: [payerId], references: [id])
receiver User @relation("payment_receiver", fields: [receiverId], references: [id])
@@index([groupId])
@@index([payerId])
@@index([receiverId])
@@map("payments")
}