22 lines
759 B
Python
22 lines
759 B
Python
from sqlalchemy.orm import Session
|
|
|
|
from app.schemas.user import UserCreate
|
|
from app.services.user import get_user_by_email, create_user
|
|
|
|
|
|
# make sure all SQL Alchemy models are imported (app.db.base) before initializing DB
|
|
# otherwise, SQL Alchemy might fail to initialize relationships properly
|
|
# for more details: https://github.com/tiangolo/full-stack-fastapi-postgresql/issues/28
|
|
|
|
|
|
def init_db(db: Session) -> None:
|
|
# Create super user if it doesn't exist
|
|
user = get_user_by_email(db, email="admin@example.com")
|
|
if not user:
|
|
user_in = UserCreate(
|
|
email="admin@example.com",
|
|
username="admin",
|
|
password="adminpassword",
|
|
is_superuser=True,
|
|
)
|
|
create_user(db, obj_in=user_in) |