apskel-pos-backend/migrations/000007_create_inventory_table.up.sql

16 lines
718 B
MySQL
Raw Permalink Normal View History

2025-07-18 20:10:29 +07:00
-- 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);