-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.prisma
240 lines (183 loc) · 5.88 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
// https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
// https://www.prisma.io/docs/orm/prisma-client/queries/full-text-search
previewFeatures = ["fullTextSearch"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Book {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
isbn13 BigInt @unique
title String
publishedDate DateTime? @db.Timestamptz(1)
imageUrl String?
authors Author[]
publisher BookSource @relation(fields: [publisherId], references: [id])
publisherId Int
format Format @relation(fields: [formatId], references: [id])
formatId Int
genre Genre @relation(fields: [genreId], references: [id])
genreId Int
priceInCents Int
quantity Int @default(0)
invoiceItems InvoiceItem[]
orderItems OrderItem[]
inventoryAdjustments InventoryAdjustment[]
}
model Author {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
name String
imageUrl String?
books Book[]
}
model BookSource {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
name String
isPublisher Boolean
books Book[]
isVendor Boolean
accountNumber String?
discountPercentage Decimal? @db.Decimal(5, 4)
invoices Invoice[]
}
model Format {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
displayName String @unique
books Book[]
}
model Genre {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
displayName String @unique
books Book[]
}
model Invoice {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
invoiceNumber String
invoiceDate DateTime @db.Timestamptz(1)
dateReceived DateTime? @db.Timestamptz(1)
isCompleted Boolean @default(false)
subTotalInCents Int
taxInCents Int
totalInCents Int
vendor BookSource @relation(fields: [vendorId], references: [id])
vendorId Int
invoiceItems InvoiceItem[]
}
model InvoiceItem {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
itemCostInCents Int
quantity Int
totalCostInCents Int
invoice Invoice @relation(fields: [invoiceId], references: [id])
invoiceId Int
productType ProductType
book Book? @relation(fields: [bookId], references: [id])
bookId Int?
}
enum ProductType {
BOOK
// eventually other product types like general merchandise, etc
}
model Order {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
orderUID String @unique @default(uuid())
orderState OrderState
orderOpenedDate DateTime @db.Timestamptz(1)
orderClosedDate DateTime? @db.Timestamptz(1)
subTotalInCents Int
taxInCents Int
totalInCents Int
orderItems OrderItem[]
transactions Transaction[]
}
enum OrderState {
// "open" states
OPEN
PENDING_TRANSACTION
// "closed" states
PAID
}
model OrderItem {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
productPriceInCents Int
quantity Int
totalPriceInCents Int
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
orderId Int
productType ProductType
book Book? @relation(fields: [bookId], references: [id])
bookId Int?
}
model Transaction {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
order Order @relation(fields: [orderUID], references: [orderUID], onDelete: Cascade)
orderUID String
amountInCents Int
transactionUID String @unique @default(uuid())
status TransactionStatus
transactionType TransactionType
squareCheckout SquareCheckout?
}
enum TransactionStatus {
// initial state
PENDING
// terminal states
CANCELLED
COMPLETE
}
enum TransactionType {
SQUARE_CHECKOUT
}
model SquareCheckout {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
checkoutId String
amountInCents Int
status String
paymentType String?
cancelReason String?
transaction Transaction @relation(fields: [transactionUID], references: [transactionUID], onDelete: Cascade)
transactionUID String @unique
}
model InventoryAdjustment {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
updatedQuantity Int
reason InventoryAdjustmentReason @relation(fields: [reasonId], references: [id])
reasonId Int
productType ProductType
book Book? @relation(fields: [bookId], references: [id])
bookId Int?
}
model InventoryAdjustmentReason {
id Int @id @default(autoincrement())
createdAt DateTime @default(now()) @db.Timestamptz(3)
updatedAt DateTime? @updatedAt @db.Timestamptz(3)
displayName String @unique
inventoryAdjustments InventoryAdjustment[]
}