auto_trade_sys/backend/database/add_stop_take_profit_prices.sql
薇薇安 8886b03021 a
2026-01-18 00:16:40 +08:00

40 lines
1.5 KiB
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 表添加止损止盈价格字段
-- 用于存储实际使用的止损止盈价格考虑了ATR等动态计算
-- 检查字段是否存在,如果不存在则添加
SET @dbname = DATABASE();
SET @tablename = 'trades';
SET @columnname = 'stop_loss_price';
SET @preparedStatement = (SELECT IF(
(
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
WHERE
(TABLE_SCHEMA = @dbname)
AND (TABLE_NAME = @tablename)
AND (COLUMN_NAME = @columnname)
) > 0,
"SELECT 'Column stop_loss_price already exists.' AS result;",
CONCAT("ALTER TABLE ", @tablename, " ADD COLUMN ", @columnname, " DECIMAL(20, 8) NULL COMMENT '实际使用的止损价格考虑了ATR等动态计算';")
));
PREPARE alterIfNotExists FROM @preparedStatement;
EXECUTE alterIfNotExists;
DEALLOCATE PREPARE alterIfNotExists;
SET @columnname2 = 'take_profit_price';
SET @preparedStatement2 = (SELECT IF(
(
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
WHERE
(TABLE_SCHEMA = @dbname)
AND (TABLE_NAME = @tablename)
AND (COLUMN_NAME = @columnname2)
) > 0,
"SELECT 'Column take_profit_price already exists.' AS result;",
CONCAT("ALTER TABLE ", @tablename, " ADD COLUMN ", @columnname2, " DECIMAL(20, 8) NULL COMMENT '实际使用的止盈价格考虑了ATR等动态计算';")
));
PREPARE alterIfNotExists2 FROM @preparedStatement2;
EXECUTE alterIfNotExists2;
DEALLOCATE PREPARE alterIfNotExists2;
SELECT 'Migration completed: Added stop_loss_price and take_profit_price columns to trades table.' AS result;