-- v0.401 M1: Product previews (audio demo files)
-- Prerequisite: products table exists

DO $$
BEGIN
  IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'products') THEN
    IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'product_previews') THEN
      CREATE TABLE product_previews (
        id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
        product_id UUID NOT NULL REFERENCES products(id) ON DELETE CASCADE,
        file_path VARCHAR(512) NOT NULL,
        duration_sec INTEGER,
        created_at TIMESTAMPTZ DEFAULT NOW()
      );
      CREATE INDEX idx_product_previews_product_id ON product_previews(product_id);
    END IF;
  END IF;
END $$;
