-- Migration: Add per-store Qdrant credentials with fallback to default
-- Date: 2025-11-24
-- Description: Allow stores to override default Qdrant connection settings

-- Add Qdrant connection fields to stores table
ALTER TABLE stores
  ADD COLUMN IF NOT EXISTS qdrant_url text,
  ADD COLUMN IF NOT EXISTS qdrant_api_key text;

-- Add comments
COMMENT ON COLUMN stores.qdrant_url IS 'Custom Qdrant server URL for this store. If NULL, uses DEFAULT_QDRANT_URL from Supabase secrets (https://qdrant-1.shop.static.shopcall.ai:6334)';
COMMENT ON COLUMN stores.qdrant_api_key IS 'Custom Qdrant API key for this store. If NULL, uses DEFAULT_QDRANT_SECRET from Supabase secrets';

-- Create index for stores with custom Qdrant settings
CREATE INDEX IF NOT EXISTS idx_stores_custom_qdrant ON stores(id) WHERE qdrant_url IS NOT NULL OR qdrant_api_key IS NOT NULL;
