first commit
This commit is contained in:
commit
34ea15a54d
246 changed files with 18660 additions and 0 deletions
40
backend/scripts/seed_admin.py
Normal file
40
backend/scripts/seed_admin.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
"""Ensure default admin user exists (catalog admin dashboard)."""
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
|
||||
|
||||
from sqlalchemy import select
|
||||
|
||||
from app.core.config import get_settings
|
||||
from app.core.security import hash_password
|
||||
from app.db.session import SessionLocal
|
||||
from app.models.entities import AdminUser
|
||||
from app.models.enums import AdminRole
|
||||
|
||||
|
||||
def main() -> None:
|
||||
settings = get_settings()
|
||||
db = SessionLocal()
|
||||
try:
|
||||
email = settings.admin_email.strip().lower()
|
||||
existing = db.scalar(select(AdminUser).where(AdminUser.email == email))
|
||||
if not existing:
|
||||
db.add(
|
||||
AdminUser(
|
||||
email=email,
|
||||
hashed_password=hash_password(settings.admin_password),
|
||||
role=AdminRole.super_admin,
|
||||
)
|
||||
)
|
||||
db.commit()
|
||||
print(f"Created admin user: {email}")
|
||||
else:
|
||||
print(f"Admin user already exists: {email}")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue