dilomere
PPrisma
•Created by dilomere on 4/15/2025 in #help-and-questions
Schema Troubleshooting
generator client {
provider = "prisma-client-js"
previewFeatures = ["metrics"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model User {
userID Int @id @default(autoincrement()) //primary key of the user table
username String @unique
password String
email String @unique
emailVerified Boolean @default(false)
listings Listing[] //one to many relationship. One user can have many listing
allBids Bid[] // one to many relationship. One user can have many bids
}
model Listing {
listingID Int @id @default(autoincrement()) //primary key of the Listing table
sellerID Int //foreign key of the user table is stored here. This is the user who is creating the listing
listCreationTimestamp DateTime @default(now())
listExpirationTimestamp DateTime @default(dbgenerated("DATE_ADD(NOW(), INTERVAL 2 DAY)")) //when the auction is over
closedListing String @default("open")
listTitle String
listDesc String?
listImg Bytes? @db.LongBlob
currentBid Int @default(0) //remove from schema to futher normalize, we can use this value by joining the bid table
creator User @relation(fields: [sellerID], references: [userID]) highBider Bid? //one to one relation. } model Bid { bidID Int @id @default(autoincrement()) //primary key of the table of the Bid table listID Int @unique //foreign key of the listing table. represents the listing that users are bidding on. bidderID Int //foreign key of the user table. represents the user who is bidding on a listing value Int @default(0) //must be greater than 0 bidder User @relation(fields: [bidderID], references: [userID]) //establishing the foreign key of the user table. bidOnListing Listing @relation(fields: [listID], references: [listingID]) //establishing the foreign key of the Listing table. }
creator User @relation(fields: [sellerID], references: [userID]) highBider Bid? //one to one relation. } model Bid { bidID Int @id @default(autoincrement()) //primary key of the table of the Bid table listID Int @unique //foreign key of the listing table. represents the listing that users are bidding on. bidderID Int //foreign key of the user table. represents the user who is bidding on a listing value Int @default(0) //must be greater than 0 bidder User @relation(fields: [bidderID], references: [userID]) //establishing the foreign key of the user table. bidOnListing Listing @relation(fields: [listID], references: [listingID]) //establishing the foreign key of the Listing table. }
5 replies