I tried to create a database for a room management sytem and I'm confused about the relations and couldn't find helpful resources on the internet can you tell me if there is anything wrong with this prisma script? as I want to control it in expressJs and make an application based on it
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model Guest {
guestId String @id @default(uuid())
name String
phone String @unique()
address String?
nationality String
Reservation Reservation[] @relation("GuestReservation")
}
model Reservation {
reservationId Int @id @default(autoincrement())
checkIn DateTime
checkOut DateTime
Guest Guest @relation("GuestReservation", fields: [guestId], references: [guestId], onDelete: Cascade)
guestId String
visitors Int
Room Room @relation("RoomReservation", fields: [roomId], references: [roomId], onDelete: Cascade)
type ReservationType
roomId Int
Bill Bill? @relation("BillReservation")
}
enum ReservationType {
Booking
Contract
Booked
Canceled
}
model Room {
roomId Int @id @default(autoincrement())
price Float
type Type
Reservation Reservation[] @relation("RoomReservation")
}
enum Type {
Single
Double
Triple
}
model Bill {
invoiceNo String @id @default(uuid())
Reservation Reservation @relation("BillReservation", fields: [reservationId], references: [reservationId], onDelete: Cascade)
reservationId Int @unique()
roomService Float @default(0)
paymentMode Payment
Service Service[]
}
enum Payment {
Cash
Visa
}
model Service {
serviceId String @id @default(uuid())
type ServiceType
name String
price Float
Bill Bill @relation(fields: [billInvoiceNo], references: [invoiceNo], onDelete: Cascade)
billInvoiceNo String
}
enum ServiceType {
Bar
Laundry
}
I tried to make a crud for each entity but I end up with relational erros such as foregin key and stuff like that which means there is something wrong with my relations.
Your schema is valid, though I would recommend keeping consistency while defining id for your tables. Some of the tables have id of string type while some are of numeric type.
Here's an example of queries to create entites for your models.
Here's the query response: