import sqlite3 conn = sqlite3.connect('it_smart_desk.db') cursor = conn.cursor() # 添加三个缺失的列 alterations = [ ("impact_scope", "INTEGER", "0"), ("is_blocking", "BOOLEAN", "0"), ("emotion_state", "VARCHAR(20)", "'normal'"), ] for col_name, col_type, default_val in alterations: try: cursor.execute(f"ALTER TABLE conversations ADD COLUMN {col_name} {col_type} NOT NULL DEFAULT {default_val}") print(f"ADDED: {col_name}") except sqlite3.OperationalError as e: if "duplicate column" in str(e).lower(): print(f"SKIP: {col_name} already exists") else: print(f"ERROR: {col_name} — {e}") conn.commit() # Verify cursor.execute('PRAGMA table_info(conversations)') cols = [row[1] for row in cursor.fetchall()] for m in ['impact_scope', 'is_blocking', 'emotion_state']: status = "EXISTS" if m in cols else "MISSING!" print(f'Verify {m}: {status}') conn.close() print("\nDone — restart the backend server for changes to take effect.")