Commit e016d68a by 江名洋

refactor(db): 优化建表SQL与列兼容性检查逻辑

1 parent d8632d28
......@@ -206,12 +206,16 @@ class StrategyService:
try:
with conn.cursor() as cur:
cur.execute(sql)
# 兼容旧表:添加 monitor_refresh_time 列(忽略 Duplicate column 错误)
try:
# 兼容旧表:仅在列不存在时添加 monitor_refresh_time
cur.execute("""
SELECT COUNT(*) FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE()
AND TABLE_NAME = 'strategy_analysis_result'
AND COLUMN_NAME = 'monitor_refresh_time'
""")
if cur.fetchone()[0] == 0:
cur.execute(alter_sql)
except Exception as e:
if "Duplicate column" not in str(e):
raise
logger.info("[Strategy] added monitor_refresh_time column")
conn.commit()
logger.info("[Strategy] result table ensured")
finally:
......
This diff could not be displayed because it is too large.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!