diff --git a/app/database.py b/app/database.py index ff6e992..044c62b 100644 --- a/app/database.py +++ b/app/database.py @@ -80,15 +80,15 @@ async def _create_initial_admin(): return async with AsyncSessionLocal() as session: - # Check if admin already exists + # Check if username already exists (any role) result = await session.execute( - text("SELECT id FROM agents WHERE username = :username AND role = 'admin'"), + text("SELECT id, role FROM agents WHERE username = :username"), {"username": settings.INITIAL_ADMIN_USERNAME} ) existing = result.fetchone() if existing: - return # Admin already exists + return # Username already taken, skip creation # Create admin user with bcrypt hash password_hash = bcrypt.hashpw(