44Run this script to create the default admin user:
55 python -m app.db.init_db
66"""
7+
78import asyncio
89
910from fastapi_users .password import PasswordHelper
@@ -19,20 +20,17 @@ async def init_db():
1920
2021 IMPORTANT:
2122 - Passwords are stored hashed in the DB (see User.hashed_password).
22- - This script will create OR update a default admin user for local development.
23+ - This script will create or update a default admin user for local development.
2324 """
2425 admin_email = "admin@example.com"
2526 admin_password = "admin" # pragma: allowlist secret # nosec B105
2627
2728 password_helper = PasswordHelper ()
2829
2930 async with async_session_maker () as session :
30- # Look up the canonical seed user.
3131 result = await session .execute (
3232 select (User ).where (User .email == admin_email )
3333 )
34-
35- # Be resilient to relationship eager-loads that can duplicate rows.
3634 existing_user = result .unique ().scalar_one_or_none ()
3735
3836 created = False
@@ -44,7 +42,6 @@ async def init_db():
4442 admin_user = User (email = admin_email )
4543 session .add (admin_user )
4644
47- # Ensure the account is a usable admin for local development.
4845 admin_user .hashed_password = password_helper .hash (admin_password )
4946 admin_user .role = Role .ADMIN .value
5047 admin_user .is_active = True
@@ -54,14 +51,14 @@ async def init_db():
5451 await session .commit ()
5552
5653 print (
57- "[SUCCESS] Created default admin user with the following details ."
54+ "[SUCCESS] Created default admin user."
5855 if created
59- else "[SUCCESS] Updated default admin user with the following details ."
56+ else "[SUCCESS] Updated default admin user."
6057 )
6158 print (f" Email: { admin_email } " )
62- print (f" Password: { admin_password } " )
6359 print (f" Role: { Role .ADMIN .value } " )
64- print ("\n IMPORTANT: Change this password after first login." )
60+ print (" Default development credentials have been configured." )
61+ print ("\n IMPORTANT: Change the default password after first login." )
6562
6663
6764if __name__ == "__main__" :
0 commit comments