import argparse import sys from app.services.auth_service import get_user_by_username from app.services.db import db_connection def promote_user(email: str) -> int: user = get_user_by_username(email) if not user: print(f"User not found: {email}", file=sys.stderr) return 1 with db_connection() as conn: with conn: with conn.cursor() as cur: cur.execute( """ UPDATE app_user SET role = 'SUPER_ADMIN', is_admin = TRUE, is_super_admin = TRUE WHERE id = %s """, (user["id"],), ) print(f"Promoted {email} to SUPER_ADMIN") return 0 def main() -> int: parser = argparse.ArgumentParser(description="Promote an existing user to SUPER_ADMIN.") parser.add_argument("email", help="User email to promote") args = parser.parse_args() return promote_user(args.email.strip()) if __name__ == "__main__": raise SystemExit(main())