-- ============================================================================ -- SCHEMA: investment -- DESCRIPTION: Agregar columnas faltantes a tablas existentes -- VERSION: 1.0.0 -- CREATED: 2026-01-10 -- DEPENDS: investment/001_agent_allocations.sql -- ============================================================================ -- ============================================================================ -- MODIFICACIONES A agent_configs -- ============================================================================ -- Agregar columna name ALTER TABLE investment.agent_configs ADD COLUMN IF NOT EXISTS name VARCHAR(100) DEFAULT ''; -- Agregar columna target_return_percent ALTER TABLE investment.agent_configs ADD COLUMN IF NOT EXISTS target_return_percent DECIMAL(5, 2) DEFAULT 0; -- Agregar columna max_drawdown_percent ALTER TABLE investment.agent_configs ADD COLUMN IF NOT EXISTS max_drawdown_percent DECIMAL(5, 2) DEFAULT 0; -- Comentarios COMMENT ON COLUMN investment.agent_configs.name IS 'Nombre descriptivo del agente'; COMMENT ON COLUMN investment.agent_configs.target_return_percent IS 'Retorno objetivo anual en porcentaje'; COMMENT ON COLUMN investment.agent_configs.max_drawdown_percent IS 'Drawdown máximo permitido en porcentaje'; -- ============================================================================ -- MODIFICACIONES A agent_allocations -- ============================================================================ -- Agregar columna total_profit_distributed ALTER TABLE investment.agent_allocations ADD COLUMN IF NOT EXISTS total_profit_distributed DECIMAL(15, 4) DEFAULT 0; -- Agregar columna total_fees_paid ALTER TABLE investment.agent_allocations ADD COLUMN IF NOT EXISTS total_fees_paid DECIMAL(15, 4) DEFAULT 0; -- Agregar columna lock_expires_at ALTER TABLE investment.agent_allocations ADD COLUMN IF NOT EXISTS lock_expires_at TIMESTAMPTZ; -- Comentarios COMMENT ON COLUMN investment.agent_allocations.total_profit_distributed IS 'Total de ganancias distribuidas al usuario'; COMMENT ON COLUMN investment.agent_allocations.total_fees_paid IS 'Total de comisiones pagadas'; COMMENT ON COLUMN investment.agent_allocations.lock_expires_at IS 'Fecha de expiración del periodo de bloqueo'; -- ============================================================================ -- MODIFICACIONES A ml.prediction_outcomes -- ============================================================================ -- Agregar columna verification_source ALTER TABLE ml.prediction_outcomes ADD COLUMN IF NOT EXISTS verification_source VARCHAR(100); -- Agregar columna notes ALTER TABLE ml.prediction_outcomes ADD COLUMN IF NOT EXISTS notes TEXT; -- Comentarios COMMENT ON COLUMN ml.prediction_outcomes.verification_source IS 'Fuente de verificación del resultado (manual, API, etc.)'; COMMENT ON COLUMN ml.prediction_outcomes.notes IS 'Notas adicionales sobre el resultado'; -- ============================================================================ -- INDICES ADICIONALES -- ============================================================================ -- Indice para buscar allocations con lock activo CREATE INDEX IF NOT EXISTS idx_alloc_lock ON investment.agent_allocations(lock_expires_at) WHERE lock_expires_at IS NOT NULL; -- Indice para buscar outcomes por source CREATE INDEX IF NOT EXISTS idx_pred_out_source ON ml.prediction_outcomes(verification_source) WHERE verification_source IS NOT NULL;