backend: api: Create database tables at startup

We might need to use Alembic for schema migrations at some point, but
until then, creating the database tables when the application first
starts will work fine.
master
Dustin 2022-01-25 21:42:40 -06:00
parent e33502eee1
commit 0ab0ef8874
1 changed files with 8 additions and 1 deletions

View File

@ -2,8 +2,9 @@
from typing import Awaitable, Callable
import fastapi
import sqlalchemy
from .. import __version__
from .. import __version__, tables
from ..config import Configuration
from .context import Context
@ -22,6 +23,12 @@ context = Context()
context.config = Configuration()
@app.on_event('startup')
def start() -> None:
engine = sqlalchemy.create_engine(context.config.database.url)
tables.metadata.create_all(engine)
@app.middleware('http')
async def context_middleware(
request: fastapi.Request,