""" Notes
This script must be run as a module, so: 
python -m app.scripts.promote_admin  (a dotted module name: not "/" path and not ".py" at the end)

python -m <module> tells Python "run this module as a script, but treat it as part of a package" — it's different from just pointing Python at a file path.

Without -m: python app/scripts/promote_admin.py
Python runs the file directly. It adds the file's own directory (app/scripts/) to sys.path, but not the project root (backend-v1/).
So when the script does:
from app.database import SessionLocal
Python looks for a top-level package called app on its search path — and can't find one, because the only thing on the path is app/scripts/, not backend-v1/ (where the app/ package actually lives). You'd get ModuleNotFoundError: No module named 'app'.

With -m: python -m app.scripts.promote_admin
You give Python a dotted module path instead of a file path. Python resolves app.scripts.promote_admin by searching sys.path for a package named app, then scripts inside it, then promote_admin inside that. 
Critically, -m adds your current working directory to sys.path — so as long as you run it from backend-v1/ (where app/ lives as a sibling folder), Python finds the app package correctly, and the from app.database import ... line inside the script resolves fine.

So the rule of thumb: any script that imports from your own package using from app.xxx import yyy needs to be run with -m (from the right directory), not as a bare file path — otherwise its own internal imports break.
"""


from app.database import SessionLocal
from app.crud import get_user_by_username


USERNAMES = ["adeloaleman"]

db = SessionLocal()
for username in USERNAMES:
    user = get_user_by_username(db, username)
    if not user:
        print(f"No user named '{username}'")
    else:
        user.is_admin = True
        db.commit()
        print(f"'{username}' is now admin")
db.close()
