pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
935 B
24 lines
935 B
from app import crud
|
|
from app.core.config import settings
|
|
from app.schemas.user import UserCreate
|
|
|
|
# make sure all SQL Alchemy models are imported 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
|
|
from app.db import base # noqa: F401
|
|
|
|
|
|
def init_db(db_session):
|
|
# Tables should be created with Alembic migrations
|
|
# But if you don't want to use migrations, create
|
|
# the tables un-commenting the next line
|
|
# Base.metadata.create_all(bind=engine)
|
|
|
|
user = crud.user.get_by_email(db_session, email=settings.FIRST_SUPERUSER)
|
|
if not user:
|
|
user_in = UserCreate(
|
|
email=settings.FIRST_SUPERUSER,
|
|
password=settings.FIRST_SUPERUSER_PASSWORD,
|
|
is_superuser=True,
|
|
)
|
|
user = crud.user.create(db_session, obj_in=user_in) # noqa: F841
|
|
|