Don't create the database from the application.

Use alembic.
This commit is contained in:
2025-06-22 18:57:44 +02:00
parent 82ec7fabb4
commit c7ecc3f365
2 changed files with 3 additions and 5 deletions

View File

@ -23,7 +23,7 @@ from .settings import BackendSettings
LOG = logging.getLogger(__name__)
def init_backend_app(settings: BackendSettings) -> FastAPI:
def init_backend_app(settings: BackendSettings, create_db: bool = False) -> FastAPI:
"""Initialize backend app."""
@asynccontextmanager
@ -31,6 +31,7 @@ def init_backend_app(settings: BackendSettings) -> FastAPI:
"""Create database before starting the server."""
LOG.debug("Running lifespan")
engine = get_async_engine(settings.async_db_url)
if create_db:
await init_db_async(engine)
yield

View File

@ -21,7 +21,6 @@ from .models import (
ClientAccessPolicy,
ClientSecret,
SubSystem,
init_db,
)
from .settings import BackendSettings
@ -50,7 +49,6 @@ def generate_token(
) -> str:
"""Generate a token."""
engine = get_engine(settings.db_url)
init_db(engine)
with Session(engine) as session:
token = create_api_token(session, subsystem)
return token
@ -63,7 +61,6 @@ def add_system_tokens(settings: BackendSettings) -> None:
return
engine = get_engine(settings.db_url)
init_db(engine)
tokens: list[tuple[str, SubSystem]] = []
if admin_token := settings.admin_token:
tokens.append((admin_token, SubSystem.ADMIN))