diff --git a/.devops/monitor.py b/.devops/monitor.py
index ff208f3..2f6e540 100644
--- a/.devops/monitor.py
+++ b/.devops/monitor.py
@@ -1667,6 +1667,34 @@ class DeploymentServer:
border-radius: 3px;
margin-bottom: 20px;
}}
+ .history-container {{
+ margin-top: 15px;
+ max-height: 200px;
+ overflow-y: auto;
+ border: 1px solid #ddd;
+ border-radius: 3px;
+ background-color: #fafafa;
+ }}
+ .history-item {{
+ padding: 10px;
+ border-bottom: 1px solid #eee;
+ cursor: pointer;
+ transition: background-color 0.2s;
+ font-family: 'Courier New', monospace;
+ font-size: 13px;
+ }}
+ .history-item:hover {{
+ background-color: #e3f2fd;
+ }}
+ .history-item:last-child {{
+ border-bottom: none;
+ }}
+ .history-empty {{
+ padding: 20px;
+ text-align: center;
+ color: #999;
+ font-size: 14px;
+ }}
@@ -1706,6 +1734,17 @@ class DeploymentServer:
+
+
+
+
@@ -2008,6 +2047,9 @@ class DeploymentServer:
row_dict[col] = values[i] if i < len(values) else None
data_rows.append(row_dict)
+ # 保存SQL历史记录
+ save_sql_history(database, sql)
+
return jsonify({
'success': True,
'data': data_rows,
@@ -2017,6 +2059,19 @@ class DeploymentServer:
except Exception as e:
return jsonify({'success': False, 'error': str(e)})
+ @self.app.route('/api/database/history')
+ def get_sql_history():
+ """获取SQL历史记录API"""
+ try:
+ db_name = request.args.get('db')
+ if not db_name:
+ return jsonify({'success': False, 'error': '缺少数据库名称'})
+
+ history = load_sql_history(db_name)
+ return jsonify({'success': True, 'history': history})
+ except Exception as e:
+ return jsonify({'success': False, 'error': str(e)})
+
@self.app.route('/
')
def deploy_project(project_name):
"""触发项目部署"""
@@ -2047,6 +2102,47 @@ class DeploymentServer:
self.app.run(host='0.0.0.0', port=self.port, debug=False, use_reloader=False)
+def save_sql_history(database, sql):
+ """保存SQL历史记录到文件"""
+ try:
+ history_dir = Path('.devops/sql_history')
+ history_dir.mkdir(parents=True, exist_ok=True)
+
+ history_file = history_dir / f'{database}.json'
+
+ # 读取现有历史记录
+ history = []
+ if history_file.exists():
+ with open(history_file, 'r', encoding='utf-8') as f:
+ history = json.load(f)
+
+ # 添加新记录(去重)
+ if sql not in history:
+ history.insert(0, sql) # 插入到开头
+ # 只保留最近10条
+ history = history[:10]
+
+ # 保存到文件
+ with open(history_file, 'w', encoding='utf-8') as f:
+ json.dump(history, f, ensure_ascii=False, indent=2)
+ except Exception as e:
+ Logger.warning(f"保存SQL历史记录失败: {e}")
+
+
+def load_sql_history(database):
+ """从文件加载SQL历史记录"""
+ try:
+ history_file = Path('.devops/sql_history') / f'{database}.json'
+
+ if history_file.exists():
+ with open(history_file, 'r', encoding='utf-8') as f:
+ return json.load(f)
+ return []
+ except Exception as e:
+ Logger.warning(f"加载SQL历史记录失败: {e}")
+ return []
+
+
def main():
"""主函数"""
import argparse