A wheel whose top-level module is `app` collides with anything else in a user's venv, so the package that is about to be published takes the name it is published under. Only the Python package moves; the repo, the Docker WORKDIR and the compose project keep theirs. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
from sqlmodel import Session, create_engine, select
|
|
|
|
from fluksio import crud
|
|
from fluksio.core.config import settings
|
|
from fluksio.models import User, UserCreate
|
|
|
|
# A connection idle across a Postgres restart is dead but still pooled; the
|
|
# pre-ping spends a round trip to find out instead of failing the request.
|
|
engine = create_engine(str(settings.SQLALCHEMY_DATABASE_URI), pool_pre_ping=True)
|
|
|
|
|
|
# make sure all SQLModel models are imported (app.models) before initializing DB
|
|
# otherwise, SQLModel might fail to initialize relationships properly
|
|
# for more details: https://github.com/fastapi/full-stack-fastapi-template/issues/28
|
|
|
|
|
|
def init_db(session: Session) -> None:
|
|
# Tables should be created with Alembic migrations
|
|
# But if you don't want to use migrations, create
|
|
# the tables un-commenting the next lines
|
|
# from sqlmodel import SQLModel
|
|
|
|
# This works because the models are already imported and registered from app.models
|
|
# SQLModel.metadata.create_all(engine)
|
|
|
|
user = session.exec(
|
|
select(User).where(User.email == settings.FIRST_SUPERUSER)
|
|
).first()
|
|
if not user:
|
|
user_in = UserCreate(
|
|
email=settings.FIRST_SUPERUSER,
|
|
password=settings.FIRST_SUPERUSER_PASSWORD,
|
|
is_superuser=True,
|
|
)
|
|
user = crud.create_user(session=session, user_create=user_in)
|