ServerDatabase
Meal Planning & Shopping
Database tables representing scheduled diet plans, user pantry logs, and dynamic shopping lists.
Meal Planning & Shopping
This module holds records for calendars, scheduled daily meals, physical pantry inventories, shopping lists, and active items.
Migrated by: 00004_create_planning_and_shopping.sql
1. Calendars & Meal Plans
meal_plans
Defines active plan programs.
- Schema:
Column Type Constraints Default Description iduuidPRIMARY KEYgen_random_uuid()Unique plan program ID. user_iduuidNOT NULL- Foreign key referencing users.id (ON DELETE CASCADE). nametext- - Custom plan program name (e.g. 'Lean Gain Phase').start_datedateNOT NULL- Plan start date. end_datedateNOT NULL- Plan end date. is_activebooleanNOT NULLtrueTrue if this is the active plan program. created_attimestamptzNOT NULLnow()Plan created timestamp. updated_attimestamptzNOT NULLnow()Plan updated timestamp.
meal_plan_items
Individual meals scheduled on specific days under a plan.
- Schema:
Column Type Constraints Default Description iduuidPRIMARY KEYgen_random_uuid()Plan item identifier. meal_plan_iduuidNOT NULL- Foreign key referencing meal_plans.id (ON DELETE CASCADE). planned_datedateNOT NULL- Target day of calendar. meal_typetextNOT NULL- Planned meal category: 'breakfast','lunch','dinner','snack'.recipe_iduuidREFERENCES recipes(id) ON DELETE SET NULL- Reference to planned recipe. food_item_iduuidREFERENCES food_items(id) ON DELETE SET NULL- Reference to planned food item. custom_food_nametext- - Planned custom fallback label. servingsnumeric(4,2)NOT NULL1.00Target portion / servings. consumedbooleanNOT NULLfalseSet to true when checked. Triggers creation of a food_log entry. created_attimestamptzNOT NULLnow()Creation timestamp.
2. Pantry Inventory
pantry_items
Tracks the user's available cooking items at home.
- Schema:
Column Type Constraints Default Description iduuidPRIMARY KEYgen_random_uuid()Pantry record ID. user_iduuidNOT NULL- Foreign key referencing users.id (ON DELETE CASCADE). food_item_iduuidNOT NULL- Foreign key referencing food_items.id (ON DELETE CASCADE). quantitynumeric(6,2)NOT NULL- Available stock. unittextNOT NULL- Stock unit (e.g. 'g','ml','piece').expires_atdate- - Expiration check. Used to flag upcoming waste. purchased_atdate- - Purchase date. created_attimestamptzNOT NULLnow()Record creation timestamp. updated_attimestamptzNOT NULLnow()Record change timestamp.
3. Shopping Lists
shopping_lists
Shopping lists generated from meal programs.
- Schema:
id(PRIMARY KEY),user_id(foreign key users),name(list title),status(default'active', can be'completed','archived'),created_at,updated_at.
shopping_list_items
Detailed elements on a shopping list.
- Schema:
id(PRIMARY KEY),shopping_list_id(foreign key shopping_lists),food_item_id(foreign key food_items),custom_item_name,quantity,unit,is_acquired(defaultfalse),category(default'Other', e.g.,'Produce'),created_at,updated_at.