I'm trying to build a system that allows restaurants to create menus that can show based on time of day and day of week.
For example, there may be a standard menu, a happy hour menu, a specials menu, etc that all have their own items per menu and pricing per item. A cheese pizza could be $10 on Friday 10AM-2PM and $5.00 3PM - 5PM.
What's a good way to design the database so items can have various pricing (based on time of day and day of week) as well as be associated to various 'menus' (in order to categorize them)?
I currently have a system that doesn't really allow for this (since time-based menus weren't needed at the time).
*Would I need a menu_items_times table with a column for price, time start, time end?*
venues table - each individual restraunt (primary_menu_id) relates to a menu_id from menus table
+------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+----------------+
| venue_id | bigint(20) | NO | PRI | None | auto_increment |
| name | varchar(256) | NO | | None | |
| primary_menu_id | bigint(20) | NO | | NULL | |
+------------------+--------------+------+-----+---------+----------------+
menus table each menu and what venue it belongs to
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| menu_id | bigint(20) | NO | PRI | None | auto_increment |
| venue_id | bigint(20) | NO | | None |
| name | varchar(256) | NO | | None | |
+----------+--------------+------+-----+---------+----------------+
menu_items table each individual menu item for a menu and what category (ie. 'drinks', 'food', 'specials' category) and 'category_index' for sorting the categories.
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| menu_item_id | bigint(20) | NO | PRI | none | auto_increment |
| menu_id | bigint(20) | NO | | none | |
| name | varchar(256) | NO | | none | |
| price | float | NO | | none | |
| category | varchar(64) | NO | | none | |
| category_index| int(11) | NO | | none | |
+---------------+--------------+------+-----+---------+----------------+
menu_items_categories view
+----------------+--------------+-----------+-------------+------+---------+
| Field | Type | Collation | Attributes | NULL | Extra |
+----------------+--------------+-----------+-------------+------+---------+
| menu_id | bigint(20) | | | No | |
| category | varchar(64) | | | No | |
| category_index | int(11) | | | No | |
+----------------+--------------+-----------+-------------+------+---------+
I can see 4 ways of doing this...
Add a time_id
field to menu_items
, that contains the id of a static array that contains times ... 1=>morning, 2=>evening, 3=>all-day, etc.
Same as #1, but make the field a VARCHAR that can be search in a LIKE (%%) query ... so time_id
becomes something like ".8.9.10.11." for 8-11am, '.18.19.20.21." for 6-9pm ... a bit more messy, and LIKE queries are a little more intensive so probably not ideal.
Instead of a field in menu_items
, add another table ... menu_times
... that contains menu_item_id
and time_id
s ... this may be faster than #2. It could even contain a time_description
instead of time_id
, such as "all morning" or "happy hour".
You could put menu_times
between menus
and menu_items
... so menus
contained menu_times
, which contained menu_items
.
One thing to note about all of these solutions is that some of them require multiple menu_items
for different prices ... which is not ideal. With solutions 1-3, however, you could solve this by moving the price
into the menu_times
table.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.