16 lines
718 B
MySQL
16 lines
718 B
MySQL
|
|
-- Inventory table
|
||
|
|
CREATE TABLE inventory (
|
||
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||
|
|
outlet_id UUID NOT NULL REFERENCES outlets(id) ON DELETE CASCADE,
|
||
|
|
product_id UUID NOT NULL REFERENCES products(id) ON DELETE CASCADE,
|
||
|
|
quantity INTEGER NOT NULL DEFAULT 0 CHECK (quantity >= 0),
|
||
|
|
reorder_level INTEGER DEFAULT 0 CHECK (reorder_level >= 0),
|
||
|
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||
|
|
UNIQUE(outlet_id, product_id)
|
||
|
|
);
|
||
|
|
|
||
|
|
-- Indexes
|
||
|
|
CREATE INDEX idx_inventory_outlet_id ON inventory(outlet_id);
|
||
|
|
CREATE INDEX idx_inventory_product_id ON inventory(product_id);
|
||
|
|
CREATE INDEX idx_inventory_quantity ON inventory(quantity);
|
||
|
|
CREATE INDEX idx_inventory_updated_at ON inventory(updated_at);
|