From 53b7ee8a900374e1ca86a9808a7c94e4fb111521 Mon Sep 17 00:00:00 2001 From: Griatch Date: Sun, 2 Mar 2025 14:20:56 +0100 Subject: [PATCH] Fix superuser-creation on fully fresh db. Resolve #3735. --- evennia/server/evennia_launcher.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/evennia/server/evennia_launcher.py b/evennia/server/evennia_launcher.py index 65869bc431..ca1def0721 100644 --- a/evennia/server/evennia_launcher.py +++ b/evennia/server/evennia_launcher.py @@ -820,7 +820,7 @@ def start_evennia(pprofiler=False, sprofiler=False): if response: _, _, _, _, pinfo, sinfo = response _print_info(pinfo, sinfo) - _reactor_stop() + _reactor_stop() def _portal_started(*args): print( @@ -1460,9 +1460,15 @@ def create_game_directory(dirname): def create_superuser(): """ - Create the superuser account + Auto-create the superuser account. Returns `True` if superuser was created. """ + from evennia.accounts.models import AccountDB + + if AccountDB.objects.filter(is_superuser=True).exists(): + # if superuser already exists, do nothing here + return False + print( "\nCreate a superuser below. The superuser is Account #1, the 'owner' " "account of the server. Email is optional and can be empty.\n" @@ -1474,13 +1480,14 @@ def create_superuser(): password = environ.get("EVENNIA_SUPERUSER_PASSWORD") if (username is not None) and (password is not None) and len(password) > 0: - from evennia.accounts.models import AccountDB superuser = AccountDB.objects.create_superuser(username, email, password) superuser.save() else: django.core.management.call_command("createsuperuser", interactive=True) + return True + def check_database(always_return=False): """ @@ -1547,6 +1554,9 @@ def check_database(always_return=False): f"Database tables missing: {', '.join(missing_tables)}. " "Did you remember to run migrations?" ) + else: + create_superuser() + return True except Exception as exc: