report_legacy_accounts.py 749 B

1234567891011121314151617181920212223242526
  1. from __future__ import annotations
  2. from sqlalchemy import text
  3. from app import create_app, db
  4. def main() -> None:
  5. app = create_app()
  6. with app.app_context():
  7. exists = db.session.execute(
  8. text("SELECT to_regclass('public.users_legacy') IS NOT NULL")
  9. ).scalar_one()
  10. if not exists:
  11. print("No legacy account table found.")
  12. return
  13. rows = db.session.execute(
  14. text("SELECT username, is_admin FROM public.users_legacy ORDER BY username")
  15. )
  16. for username, is_admin in rows:
  17. role = "admin" if is_admin else "viewer"
  18. print(f"{username}\tproposed_role={role}\tpassword_reset_required=true")
  19. if __name__ == "__main__":
  20. main()