feat: Phase 2 - Authentication and authorization (T-010 to T-013)
This commit is contained in:
35
backend/app/seed.py
Normal file
35
backend/app/seed.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""
|
||||
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()
|
||||
Reference in New Issue
Block a user