-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema.prisma
150 lines (133 loc) · 4.72 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
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
generator client {
provider = "prisma-client-js"
previewFeatures = ["driverAdapters"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Product {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String
slug String @unique(map: "product_slug_idx") //The map is to create an index
category String
images String[]
brand String
description String
stock Int
price Decimal @default(0) @db.Decimal(12, 2)
rating Decimal @default(0) @db.Decimal(3, 2)
numReviews Int @default(0)
isFeatured Boolean
banner String?
createdAt DateTime @default(now()) @db.Timestamp(6)
OrderItem OrderItem[]
review Review[]
}
model User {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String @default("NO_NAME")
email String @unique(map: "user_email_idx")
emailVerified DateTime? @db.Timestamp(6)
image String?
password String?
role String @default("user")
address Json? @db.Json
paymentMethod String?
createdAt DateTime @default(now()) @db.Timestamp(6)
updatedAt DateTime @updatedAt
account Account[]
session Session[]
cartItems Cart[]
orders Order[]
review Review[]
}
model Account {
userId String @db.Uuid
type String
provider String
providerAccountId String
refresh_token String?
access_token String?
expires_at Int?
token_type String?
scope String?
id_token String?
session_state String?
createdAt DateTime @default(now()) @db.Timestamp(6)
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@id([provider, providerAccountId])
}
model Session {
sessionToken String @id
userId String @db.Uuid
expires DateTime @db.Timestamp(6)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now()) @db.Timestamp(6)
updatedAt DateTime @updatedAt
}
model VerificationToken {
identifier String
token String
expires DateTime
@@id([identifier, token])
}
model Cart {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
userId String? @db.Uuid
sessionCartId String
items Json[] @default([]) @db.Json
itemsPrice Decimal @db.Decimal(12, 2)
totalPrice Decimal @db.Decimal(12, 2)
shippingPrice Decimal @db.Decimal(12, 2)
taxPrice Decimal @db.Decimal(12, 2)
createdAt DateTime @default(now()) @db.Timestamp(6)
user User? @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model Order {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
userId String @db.Uuid
shippingAddress Json @db.Json
paymentMethod String
paymentResult Json? @db.Json
itemsPrice Decimal @db.Decimal(12, 2)
shippingPrice Decimal @db.Decimal(12, 2)
taxPrice Decimal @db.Decimal(12, 2)
totalPrice Decimal @db.Decimal(12, 2)
isPaid Boolean @default(false)
paidAt DateTime? @db.Timestamp(6)
isDelivered Boolean @default(false)
deliveredAt DateTime? @db.Timestamp(6)
createdAt DateTime @default(now()) @db.Timestamp(6)
orderItems OrderItem[]
user User @relation(fields:userId, references: [id], onDelete: Cascade)
}
model OrderItem {
orderId String @db.Uuid
productId String @db.Uuid
quantity Int
price Decimal @db.Decimal(12, 2)
name String
slug String
image String
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
order Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
@@id([orderId, productId], map:"orderItems_orderId_productId_pk")
}
model Review {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
userId String @db.Uuid
productId String @db.Uuid
rating Int
title String
description String
isVerifiedPurchase Boolean @default(true)
createdAt DateTime @default(now()) @db.Timestamp(6)
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}