-- Migración: Asegurar que ai_analysis existe en la tabla answers
-- Fecha: 2025-11-26
-- Descripción: Agrega la columna ai_analysis si no existe (para guardar el resultado del análisis de IA)

-- Agregar columna ai_analysis si no existe
DO $$ 
BEGIN
    IF NOT EXISTS (
        SELECT 1 FROM information_schema.columns 
        WHERE table_name = 'answers' 
        AND column_name = 'ai_analysis'
    ) THEN
        ALTER TABLE answers ADD COLUMN ai_analysis JSONB;
        COMMENT ON COLUMN answers.ai_analysis IS 'Resultado del análisis de IA: {status, observations, recommendation, confidence, model, provider}';
    END IF;
END $$;

-- Verificar que la columna existe
SELECT 
    column_name, 
    data_type, 
    is_nullable,
    column_default
FROM information_schema.columns 
WHERE table_name = 'answers' 
AND column_name = 'ai_analysis';

SELECT '✅ Columna ai_analysis verificada/creada en tabla answers' as status;
