#!/usr/bin/env python3 """ Migration script to add debug columns to execution_logs table """ import sqlite3 import os def migrate_execution_logs(): """Add debug columns to execution_logs table""" # Database path db_path = "data/scriptsmanager.db" if not os.path.exists(db_path): print(f"Error: Database not found at {db_path}") return False try: conn = sqlite3.connect(db_path) cursor = conn.cursor() # Check if new columns already exist cursor.execute("PRAGMA table_info(execution_logs)") columns = [row[1] for row in cursor.fetchall()] new_columns = [ ("command_executed", "TEXT"), ("conda_environment", "VARCHAR(100)"), ("working_directory", "VARCHAR(500)"), ("process_id", "INTEGER"), ("port_allocated", "INTEGER"), ] for column_name, column_type in new_columns: if column_name not in columns: print(f"Adding column: {column_name}") cursor.execute( f"ALTER TABLE execution_logs ADD COLUMN {column_name} {column_type}" ) else: print(f"Column {column_name} already exists, skipping") conn.commit() print("Migration completed successfully!") # Verify the new structure cursor.execute("PRAGMA table_info(execution_logs)") columns_after = cursor.fetchall() print("\nTable structure after migration:") for col in columns_after: print(f" {col[1]} ({col[2]})") conn.close() return True except Exception as e: print(f"Error during migration: {e}") return False if __name__ == "__main__": migrate_execution_logs()