sukjenogi-backend/app/scripts/create_admin.py
2025-09-19 16:28:03 +09:00

25 lines
759 B
Python
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from sqlalchemy.orm import Session
from app.core.database import SessionLocal, Base, engine
from app.core.security_admin import hash_password
from app.models.admin_user import AdminUser
def main():
Base.metadata.create_all(bind=engine)
db: Session = SessionLocal()
if not db.query(AdminUser).filter(AdminUser.username=="admin").first():
user = AdminUser(
username="admin",
password_hash=hash_password("admin1234"),
name="관리자",
email=None,
is_superadmin=True,
is_active=True,
)
db.add(user); db.commit()
print("✅ admin / admin1234 created")
else:
print(" admin already exists")
if __name__ == "__main__":
main()