"""
Migration: add thumbnail_url column to game_categories table.
Run from the backend/ directory:
  d:\ABCD\stemgenius_new_app\Scripts\python.exe migrate_category_thumbnail.py
"""
import asyncio
from sqlalchemy import text
from app.core.database import AsyncSessionLocal


async def main():
    async with AsyncSessionLocal() as db:
        # Check if column already exists
        result = await db.execute(text("""
            SELECT COUNT(*) FROM information_schema.COLUMNS
            WHERE TABLE_SCHEMA = DATABASE()
              AND TABLE_NAME = 'game_categories'
              AND COLUMN_NAME = 'thumbnail_url'
        """))
        count = result.scalar()
        if count:
            print("[SKIP] thumbnail_url column already exists in game_categories.")
            return

        await db.execute(text("""
            ALTER TABLE game_categories
            ADD COLUMN thumbnail_url VARCHAR(500) NULL
        """))
        await db.commit()
        print("[OK] Added thumbnail_url column to game_categories.")


asyncio.run(main())
