mirror of
https://github.com/kevin-DL/full-stack-fastapi-postgresql.git
synced 2026-01-13 10:35:30 +00:00
* Use Pydantic BaseSettings for config settings * Update fastapi dep to >=0.47.0 and email_validator to email-validator * Fix deprecation warning for Pydantic >=1.0 * Properly support old-format comma separated strings for BACKEND_CORS_ORIGINS Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
25 lines
907 B
Python
25 lines
907 B
Python
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
|
|
|
|
|
|
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)
|