Files
Aegis/backend/app/seed.py

36 lines
834 B
Python

"""
Seed script — creates the initial admin user if it does not already exist.
Usage:
python -m app.seed
"""
from app.auth import hash_password
from app.database import SessionLocal
from app.models.user import User
def seed_admin() -> None:
"""Create the default admin user when it is missing."""
db = SessionLocal()
try:
existing = db.query(User).filter(User.username == "admin").first()
if existing:
print("Admin user already exists — skipping.")
return
admin = User(
username="admin",
hashed_password=hash_password("admin123"),
role="admin",
)
db.add(admin)
db.commit()
print("Admin user created successfully.")
finally:
db.close()
if __name__ == "__main__":
seed_admin()