Update datamodel in documentation

This commit is contained in:
lasse 2025-05-26 09:05:39 +02:00
parent 19a410d553
commit 28db52dc2e

View File

@ -40,28 +40,80 @@ A web application for tracking grocery prices and shopping events. Built with Fa
## Data Model ## Data Model
### Groceries ### Core Entities
- `id`: Primary key
- `name`: Grocery name
- `price`: Current price
- `category`: Food category
- `organic`: Boolean flag
- `weight`: Weight/volume
- `weight_unit`: Unit (g, kg, ml, l, piece)
### Shops #### Groceries (`groceries` table)
- `id`: Primary key - `id`: Integer, Primary key, Auto-increment
- `name`: Shop name - `name`: String, Grocery name (indexed, required)
- `city`: Location city - `category`: String, Food category (required)
- `address`: Optional full address - `organic`: Boolean, Organic flag (default: false)
- `weight`: Float, Weight/volume (optional)
- `weight_unit`: String, Unit of measurement (default: "piece")
- Supported units: "g", "kg", "ml", "l", "piece"
- `created_at`: DateTime, Creation timestamp (auto-generated)
- `updated_at`: DateTime, Last update timestamp (auto-updated)
### Shopping Events #### Shops (`shops` table)
- `id`: Primary key - `id`: Integer, Primary key, Auto-increment
- `shop_id`: Foreign key to shops - `name`: String, Shop name (indexed, required)
- `date`: Purchase date - `city`: String, Location city (required)
- `total_amount`: Optional total cost - `address`: String, Full address (optional)
- `notes`: Optional notes - `created_at`: DateTime, Creation timestamp (auto-generated)
- `groceries`: Many-to-many relationship with amounts
#### Shopping Events (`shopping_events` table)
- `id`: Integer, Primary key, Auto-increment
- `shop_id`: Integer, Foreign key to shops (required)
- `date`: DateTime, Purchase date (required, default: current time)
- `total_amount`: Float, Total cost of shopping event (optional, auto-calculated)
- `notes`: String, Optional notes about the purchase
- `created_at`: DateTime, Creation timestamp (auto-generated)
### Association Table
#### Shopping Event Groceries (`shopping_event_groceries` table)
Many-to-many relationship between shopping events and groceries with additional data:
- `id`: Integer, Primary key, Auto-increment
- `shopping_event_id`: Integer, Foreign key to shopping_events (required)
- `grocery_id`: Integer, Foreign key to groceries (required)
- `amount`: Float, Quantity purchased in this event (required, > 0)
- `price`: Float, Price at time of purchase (required, ≥ 0)
### Relationships
```
┌─────────────────┐ ┌─────────────────────────────┐ ┌─────────────────┐
│ Shops │ │ Shopping Event Groceries │ │ Groceries │
│ │ │ (Association Table) │ │ │
│ • id │ ←──────→│ • shopping_event_id │ ←──────→│ • id │
│ • name │ 1:N │ • grocery_id │ N:M │ • name │
│ • city │ │ • amount │ │ • category │
│ • address │ │ • price │ │ • organic │
│ • created_at │ │ │ │ • weight │
└─────────────────┘ └─────────────────────────────┘ │ • weight_unit │
│ │ │ • created_at │
│ │ │ • updated_at │
│ 1:N │ └─────────────────┘
▼ │
┌─────────────────┐ │
│ Shopping Events │ ←───────────────────────┘
│ │ 1:N
│ • id │
│ • shop_id │
│ • date │
│ • total_amount │
│ • notes │
│ • created_at │
└─────────────────┘
```
### Key Features
- **Price History**: Each grocery purchase stores the price at that time, enabling price tracking
- **Flexible Quantities**: Support for decimal amounts (e.g., 1.5 kg of apples)
- **Auto-calculation**: Total amount can be automatically calculated from individual items
- **Free Items**: Supports items with price 0 (samples, promotions, etc.)
- **Audit Trail**: All entities have creation timestamps for tracking
- **Data Integrity**: Foreign key constraints ensure referential integrity
## Setup Instructions ## Setup Instructions