-- Migration 045: Add thumbnail_url columns to canonical tables
--
-- NOTE: image_url already exists in both tables from migration 041.
-- This migration adds thumbnail_url for cached thumbnail images.

DO $$
BEGIN
  -- Add thumbnail_url to store_products if not exists
  IF NOT EXISTS (
    SELECT 1 FROM information_schema.columns
    WHERE table_name = 'store_products' AND column_name = 'thumbnail_url'
  ) THEN
    ALTER TABLE store_products ADD COLUMN thumbnail_url TEXT NULL;
  END IF;

  -- Add thumbnail_url to store_product_snapshots if not exists
  IF NOT EXISTS (
    SELECT 1 FROM information_schema.columns
    WHERE table_name = 'store_product_snapshots' AND column_name = 'thumbnail_url'
  ) THEN
    ALTER TABLE store_product_snapshots ADD COLUMN thumbnail_url TEXT NULL;
  END IF;
END;
$$ LANGUAGE plpgsql;

COMMENT ON COLUMN store_products.thumbnail_url IS 'URL to cached thumbnail image';
COMMENT ON COLUMN store_product_snapshots.thumbnail_url IS 'URL to cached thumbnail image at time of snapshot';
