48 lines
1.0 KiB
Python
48 lines
1.0 KiB
Python
"""
|
|
List all users in the database
|
|
|
|
Usage:
|
|
python scripts/list_users.py
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
project_root = Path(__file__).parent.parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
from src.database.session import db_manager
|
|
from src.database.repositories import UserRepository
|
|
|
|
|
|
def list_users():
|
|
"""List all users in the database"""
|
|
session = db_manager.get_session()
|
|
try:
|
|
user_repo = UserRepository(session)
|
|
users = user_repo.get_all()
|
|
|
|
if not users:
|
|
print("No users found in database")
|
|
return
|
|
|
|
print(f"\nTotal users: {len(users)}")
|
|
print("=" * 70)
|
|
print(f"{'ID':<5} {'Username':<20} {'Role':<10} {'Created'}")
|
|
print("=" * 70)
|
|
|
|
for user in users:
|
|
created = user.created_at.strftime("%Y-%m-%d %H:%M:%S")
|
|
print(f"{user.id:<5} {user.username:<20} {user.role:<10} {created}")
|
|
|
|
print("=" * 70)
|
|
|
|
finally:
|
|
session.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
list_users()
|
|
|
|
|