from __future__ import annotations

from sqlalchemy import text

from app import create_app, db


def main() -> None:
    app = create_app()
    with app.app_context():
        exists = db.session.execute(
            text("SELECT to_regclass('public.users_legacy') IS NOT NULL")
        ).scalar_one()
        if not exists:
            print("No legacy account table found.")
            return
        rows = db.session.execute(
            text("SELECT username, is_admin FROM public.users_legacy ORDER BY username")
        )
        for username, is_admin in rows:
            role = "admin" if is_admin else "viewer"
            print(f"{username}\tproposed_role={role}\tpassword_reset_required=true")


if __name__ == "__main__":
    main()
