M3 Database Schema
The M3 database stores inventory items, locations, stock movements, and alerting. It is a PostgreSQL schema generated from Prisma migrations.
Core Tables
Section titled “Core Tables”| Table | Purpose | Notes |
|---|---|---|
properties | Inventory properties (villas) | Top-level grouping |
locations | Hierarchical storage locations | Supports parent-child locations |
zones | Grouping of locations | Optional grouping layer |
item_categories | Category tree for inventory items | Self-referencing parent-child |
inventory_items | Core inventory item records | Links to property, location, category |
item_photos | Item photo metadata | Linked to inventory_items |
stock_movements | Audit trail of stock changes | Linked to inventory_items |
linen_types | Linen type definitions | Used by linen tracking |
linen_inventory | Linen item tracking | Linked to items and types |
inventory_alerts | Low stock and condition alerts | Linked to items and properties |
inventory_snapshots | Periodic stock snapshots | Linked to properties |
consumable_types | Consumable item types | Used by consumables tracking |
consumable_items | Consumable item records | Linked to types and properties |
item_templates | Template definitions | For bulk item creation |
template_items | Items within a template | Linked to item_templates |
audit_log | System audit trail | Records changes and actions |
Key Relationships
Section titled “Key Relationships”locations.propertyId→properties.idlocations.parentId→locations.idzones.locationId→locations.iditem_categories.parentId→item_categories.idinventory_items.propertyId→properties.idinventory_items.locationId→locations.idinventory_items.zoneId→zones.idinventory_items.categoryId→item_categories.iditem_photos.itemId→inventory_items.idstock_movements.itemId→inventory_items.idstock_movements.fromLocationId→locations.idstock_movements.toLocationId→locations.idlinen_inventory.itemId→inventory_items.idlinen_inventory.linenTypeId→linen_types.idinventory_alerts.itemId→inventory_items.idinventory_alerts.propertyId→properties.idinventory_snapshots.propertyId→properties.idconsumable_items.propertyId→properties.idconsumable_items.consumableTypeId→consumable_types.idtemplate_items.templateId→item_templates.id
| Enum | Values |
|---|---|
ItemCategory | equipment, consumable, linen, operational, decor, safety, signage, kitchenware, tableware, bathroom, bedroom, outdoor, electronics, furniture |
ItemCondition | new, excellent, good, fair, needs_repair, needs_replacement |
LocationType | building, floor, room, area, zone_group, other |
StockMovementType | initial, purchase, return_item, use, damage, loss, transfer_in, transfer_out, adjustment |
AlertStatus | active, acknowledged, resolved |
inventory_itemsis the central table; most inventory data links to it directly.- Location hierarchy uses a self-referencing
locations.parentIdfor nesting.
Source
Section titled “Source”Schema extracted from D:\Development\m2-main\db_export\m3.sql.