Background
I'm building a Private Chef booking service where you can book a Chef to cook you a custom Menu. I'm having trouble creating a SQL db schema that accurately represents the domain while maintaining data integrity.
Requirements
- Customers create a
Booking
by selecting aChef
and aMenu
and choose theMenuItems
they want for eachMenuCourse
- A
Chef
defines a set ofMenuItem
that a customer can choose from to create theirBooking
- A
Menu
is a collection ofMenuCourses
. (ex. AMenu
named "Tasting Menu" is a 6 course meal, where eachMenuCourse
costs between $10-20). - A
Chef
should be able to associate theirMenuItems
with multipleMenus
andMenuCourses
. - A customer
Booking
should contain theChef
the customer selected along with theMenu
(and theMenuItems
) that will be served.Booking
price is determined by theMenu
andMenuCourse
selections (an appetizer costs less than an entree)
Problem
In my current data model, I have the following issues that I'm not sure how to fix:
A. It's possible to create a Booking
with Chef
"A", but then have a BookingMenuItem
that references a MenuItem
with Chef
"B" (all the BookingMenuItem
for a Booking
should belong to the same Chef
)
B. A Booking
references a particular Menu
(which I need for pricing, pricing is based on Menu
and MenuCourse
) however a BookingMenuItem
for that Booking
could reference a completely different Menu
or MenuCourse
Is it possible to re-design my db schema to fix the integrity problems I'm having? Or do I just have to implement these checks at the application level. Thanks!