diff --git a/backend/app/seed.py b/backend/app/seed.py index dbebc11..a39e1b5 100644 --- a/backend/app/seed.py +++ b/backend/app/seed.py @@ -64,12 +64,18 @@ def seed_admin() -> None: if not admin_email: admin_email = admin_username if "@" in admin_username else f"{admin_username}@localhost" - # Assign existing = db.query(User).filter(User.email == admin_email).first() - existing = db.query(User).filter(User.email == admin_email).first() + # Skip if ANY admin already exists — not just one matching this + # specific username/email. Matching only on the computed identifier + # is fragile: an install predating ADMIN_EMAIL has a user whose + # email was migration-backfilled to its bare username (e.g. + # "administrator"), which won't match a freshly-computed + # "...@localhost" placeholder, so every restart would otherwise + # create a new duplicate admin account. + existing = db.query(User).filter(User.role == "admin").first() # Check: existing if existing: # Call print() - print(f"Admin user '{admin_email}' already exists — skipping.") + print(f"An admin user already exists ('{existing.email}') — skipping.") # Return control to caller return