import asyncio import sys import os # Add the parent directory to sys.path to allow importing from app sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from sqlalchemy import text from app.database import engine async def add_column(): async with engine.begin() as conn: try: print("Attempting to add 'stock_code' column to 'llm_usage_logs'...") # Using raw SQL to add the column safely await conn.execute(text("ALTER TABLE llm_usage_logs ADD COLUMN IF NOT EXISTS stock_code VARCHAR(50);")) print("Success: Column 'stock_code' verified/added in 'llm_usage_logs'.") except Exception as e: print(f"Error executing migration: {e}") finally: await engine.dispose() if __name__ == "__main__": asyncio.run(add_column())