-- Migration 120: Daily baseline tracking
-- Track when each store's daily baseline payload was last saved
-- Part of Real-Time Inventory Tracking feature

-- Add column to track last baseline save time
ALTER TABLE dispensaries ADD COLUMN IF NOT EXISTS last_baseline_at TIMESTAMPTZ DEFAULT NULL;

-- Index for finding stores that need baselines
CREATE INDEX IF NOT EXISTS idx_dispensaries_baseline ON dispensaries(last_baseline_at)
WHERE crawl_enabled = TRUE;

-- Comment
COMMENT ON COLUMN dispensaries.last_baseline_at IS 'Timestamp of last daily baseline payload save. Baselines saved once per day between 12:01 AM - 3:00 AM.';
