-- Migration: Add expiry date and low-stock threshold tracking
-- Issues: #63 (expiry tracking), #67 (low-stock threshold)
-- Created: 2026-02-25

-- Add expires_at column for expiry date tracking
ALTER TABLE pantry_items
ADD COLUMN expires_at TIMESTAMP WITH TIME ZONE DEFAULT NULL;

-- Add low_stock_threshold column for low-stock alerts
ALTER TABLE pantry_items
ADD COLUMN low_stock_threshold NUMERIC(10,2) DEFAULT NULL;

-- Add comments for documentation
COMMENT ON COLUMN pantry_items.expires_at IS 'Optional expiration date for the item. Null means no expiry tracking.';
COMMENT ON COLUMN pantry_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_pantry_items_expires_at ON pantry_items(expires_at) WHERE expires_at IS NOT NULL;

-- Create index for efficient low-stock queries
CREATE INDEX idx_pantry_items_low_stock ON pantry_items(quantity, low_stock_threshold) 
WHERE low_stock_threshold IS NOT NULL;
