-- Migration: Add expiry date and low-stock threshold tracking -- Issues: #63 (expiry tracking), #67 (low-stock threshold) -- Created: 2026-02-25 -- Note: expiry_date already exists as DATE type. Adding expires_at as TIMESTAMPTZ for consistency -- and low_stock_threshold for threshold tracking. -- Add expires_at column for precise expiry date/time tracking (complementing existing expiry_date) -- We'll keep both: expiry_date (DATE) for simple day-based expiry, expires_at (TIMESTAMPTZ) for precise tracking ALTER TABLE inventory_items ADD COLUMN expires_at TIMESTAMP WITH TIME ZONE DEFAULT NULL; -- Add low_stock_threshold column for low-stock alerts ALTER TABLE inventory_items ADD COLUMN low_stock_threshold NUMERIC(10,2) DEFAULT NULL; -- Add comments for documentation COMMENT ON COLUMN inventory_items.expires_at IS 'Optional precise expiration timestamp. Complements expiry_date for items needing time-specific expiry.'; COMMENT ON COLUMN inventory_items.low_stock_threshold IS 'Minimum quantity threshold. Item is considered low-stock when quantity <= threshold. Null means no threshold set.'; -- Create index for efficient expiry queries (finding items expiring soon) CREATE INDEX idx_inventory_items_expires_at ON inventory_items(expires_at) WHERE expires_at IS NOT NULL; -- Create index for efficient low-stock queries CREATE INDEX idx_inventory_items_low_stock ON inventory_items(quantity, low_stock_threshold) WHERE low_stock_threshold IS NOT NULL;