Files
bewell-in-ua/lib/db/prisma/schema/user.prisma
2025-03-11 02:54:09 +02:00

94 lines
3.2 KiB
Plaintext

enum UserRole {
BANNED
FROZEN
OBSERVER
CUSTOMER
AGENT
USER
POWERUSER
EDITOR
ADMIN
MODERATOR
SUPERVISOR
}
model User {
id Int @id @default(autoincrement())
locale Lang @default(uk)
active Boolean?
name String?
username String? @unique
email String? @unique
emailVerified DateTime? @map("email_verified") @db.Timestamp(3)
password String? @db.VarChar(384)
image String?
// sessions Session[]
/// [UserExtendedDataType]
extendedData Json? @map("extended_data") @db.Json
// orders Order[]
favorites UserFavouriteProduct[]
orders Order[]
reviews UserProductReview[]
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(3)
updatedAt DateTime? @default(dbgenerated("NULL DEFAULT NULL ON UPDATE current_timestamp(3)")) @map("updated_at") @db.Timestamp(3)
account Account[]
//authenticator Authenticator[]
//session Session[]
@@map("users")
}
// https://stackoverflow.com/questions/72606917/get-custom-attribute-depend-on-pivot-table-in-nest-js-with-prisma-orm
model UserFavouriteProduct {
id Int @id @default(autoincrement())
status Boolean?
informAvailability Boolean? @map("inform_availability")
user User @relation(fields: [userId], references: [id])
userId Int @map("user_id")
productId Int @map("product_id")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(3)
@@unique([userId, productId])
@@map("user_favourite_products")
}
// https://stackoverflow.com/questions/67065859/modeling-a-rating-system-in-prisma
model UserProductReview {
id Int @id @default(autoincrement())
rating Decimal?
body String @db.Text
productId Int @map("product_id")
user User @relation(fields: [userId], references: [id])
userId Int @map("user_id")
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(3)
updatedAt DateTime? @default(dbgenerated("NULL DEFAULT NULL ON UPDATE current_timestamp(3)")) @map("updated_at") @db.Timestamp(3)
@@unique([userId, productId])
@@map("user_product_reviews")
}
model Account {
id Int @id @default(autoincrement())
userId Int @unique @map("user_id")
role UserRole @default(CUSTOMER)
active Boolean @default(true)
addess String?
type String
provider String
providerAccountId String @map("provider_account_id")
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
refresh_token_expires_in Int?
user User @relation(fields: [userId], references: [id])
@@unique([provider, providerAccountId])
@@index([userId])
@@map("accounts")
}