auto_trade_sys/backend/database/add_entry_context.sql
薇薇安 380ce7cda9 a
2026-01-31 10:14:57 +08:00

22 lines
942 B
SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 为 trades 表添加「入场思路/过程」字段,便于事后分析策略执行效果
-- 存储 JSONsignal_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;