-- 为 trades 表添加「入场思路/过程」字段，便于事后分析策略执行效果
-- 存储 JSON：signal_strength, market_regime, trend_4h, change_percent, rsi, reason, volume_confirmed 等

-- 使用动态 SQL 检查列是否存在（兼容已有库）
SET @column_exists = (
    SELECT COUNT(*)
    FROM information_schema.columns
    WHERE table_schema = DATABASE()
    AND table_name = 'trades'
    AND column_name = 'entry_context'
);

SET @sql = IF(@column_exists = 0,
    'ALTER TABLE `trades` ADD COLUMN `entry_context` JSON NULL COMMENT ''入场时的思路与过程（信号强度、市场状态、趋势、过滤通过情况等），便于综合分析策略执行效果'' AFTER `entry_reason`',
    'SELECT "entry_context 列已存在，跳过添加" AS message'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

SELECT 'Migration completed: entry_context added to trades (if not exists).' AS result;
