#!/usr/bin/env python # -*- coding: utf-8 -*- """ 为experiments表添加script_data字段,用于存储动态脚本返回的数据 """ import sqlite3 from pathlib import Path def add_script_data_column(): """添加script_data字段到experiments表""" db_path = Path(__file__).parent / "experiments.db" try: conn = sqlite3.connect(str(db_path)) cursor = conn.cursor() # 检查字段是否已存在 cursor.execute("PRAGMA table_info(experiments)") columns = [row[1] for row in cursor.fetchall()] if 'script_data' in columns: print("✅ script_data字段已存在,无需添加") else: # 添加script_data字段 cursor.execute(""" ALTER TABLE experiments ADD COLUMN script_data TEXT """) conn.commit() print("✅ 成功添加script_data字段到experiments表") # 显示更新后的表结构 cursor.execute("PRAGMA table_info(experiments)") print("\n更新后的表结构:") for row in cursor.fetchall(): print(f" {row[1]}: {row[2]} {row[3] if row[3] else ''}") conn.close() except Exception as e: print(f"❌ 添加字段失败: {e}") raise if __name__ == "__main__": add_script_data_column()