""" Script to update user to admin status and/or reset password. Run: python backend/scripts/make_admin.py """ import asyncio import sys import os # Add backend to path sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) from sqlmodel import select from sqlmodel.ext.asyncio.session import AsyncSession from app.core.database import get_session, engine from app.models.user import User async def make_admin(email: str, new_password: str = None): """Make user a superuser and optionally reset password.""" async with AsyncSession(engine) as session: # Find user stmt = select(User).where(User.email == email) result = await session.execute(stmt) user = result.scalar_one_or_none() if not user: print(f"❌ User not found: {email}") return False # Update to superuser user.is_superuser = True user.is_verified = True user.is_active = True # Update password if provided if new_password: user.hashed_password = User.get_password_hash(new_password) print(f"✅ Password updated for {email}") session.add(user) await session.commit() print(f"✅ User {email} is now superuser (admin)") print(f" ID: {user.id}") print(f" Tenant: {user.tenant_id}") print(f" is_superuser: {user.is_superuser}") print(f" is_verified: {user.is_verified}") return True if __name__ == "__main__": email = "axeroni.s2@gmail.com" password = "vector7678" asyncio.run(make_admin(email, password))