feat: add expiry tracking and low-stock threshold (#63 #67) #70

Merged
makiolaj merged 6 commits from feature/issue-63-67-expiry-lowstock-fields into develop 2026-02-25 01:24:26 +00:00
Showing only changes of commit c5870f9e6f - Show all commits

View File

@@ -2,21 +2,25 @@
-- Issues: #63 (expiry tracking), #67 (low-stock threshold) -- Issues: #63 (expiry tracking), #67 (low-stock threshold)
-- Created: 2026-02-25 -- Created: 2026-02-25
-- Add expires_at column for expiry date tracking -- Note: expiry_date already exists as DATE type. Adding expires_at as TIMESTAMPTZ for consistency
ALTER TABLE pantry_items -- 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 COLUMN expires_at TIMESTAMP WITH TIME ZONE DEFAULT NULL;
-- Add low_stock_threshold column for low-stock alerts -- Add low_stock_threshold column for low-stock alerts
ALTER TABLE pantry_items ALTER TABLE inventory_items
ADD COLUMN low_stock_threshold NUMERIC(10,2) DEFAULT NULL; ADD COLUMN low_stock_threshold NUMERIC(10,2) DEFAULT NULL;
-- Add comments for documentation -- 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 inventory_items.expires_at IS 'Optional precise expiration timestamp. Complements expiry_date for items needing time-specific expiry.';
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.'; 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 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 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 for efficient low-stock queries
CREATE INDEX idx_pantry_items_low_stock ON pantry_items(quantity, low_stock_threshold) CREATE INDEX idx_inventory_items_low_stock ON inventory_items(quantity, low_stock_threshold)
WHERE low_stock_threshold IS NOT NULL; WHERE low_stock_threshold IS NOT NULL;