"""Migration: Add use_global_* flags to kitchen_settings for central stack credential delegation."""
import asyncio
from sqlalchemy import text
from database import engine


async def migrate():
    async with engine.begin() as conn:
        for col in [
            "ALTER TABLE kitchen_settings ADD COLUMN IF NOT EXISTS use_global_smtp BOOLEAN DEFAULT FALSE",
            "ALTER TABLE kitchen_settings ADD COLUMN IF NOT EXISTS use_global_nextcloud BOOLEAN DEFAULT FALSE",
            "ALTER TABLE kitchen_settings ADD COLUMN IF NOT EXISTS use_global_newbook BOOLEAN DEFAULT FALSE",
            "ALTER TABLE kitchen_settings ADD COLUMN IF NOT EXISTS use_global_resos BOOLEAN DEFAULT FALSE",
            "ALTER TABLE kitchen_settings ADD COLUMN IF NOT EXISTS use_global_sambapos BOOLEAN DEFAULT FALSE",
            "ALTER TABLE kitchen_settings ADD COLUMN IF NOT EXISTS use_global_azure BOOLEAN DEFAULT FALSE",
        ]:
            try:
                await conn.execute(text(col))
            except Exception:
                pass
    print("+ Global settings flags migration complete")


if __name__ == "__main__":
    asyncio.run(migrate())
