Don't create the database from the application.
Use alembic.
This commit is contained in:
@ -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,7 +31,8 @@ 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)
|
||||
await init_db_async(engine)
|
||||
if create_db:
|
||||
await init_db_async(engine)
|
||||
yield
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
@ -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))
|
||||
|
||||
Reference in New Issue
Block a user