From c2b673fdd34b664a5e2881ae3ab29df8e5d6b99f Mon Sep 17 00:00:00 2001 From: Motoko Date: Mon, 30 Mar 2026 16:45:13 +0000 Subject: [PATCH] Fix: Check for any existing user, not just admin role --- app/database.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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(