From 7995c0090ae63dc9e53e87ba0b6c24ef2c3a1ed3 Mon Sep 17 00:00:00 2001 From: jcadam14 <41971533+jcadam14@users.noreply.github.com> Date: Wed, 24 Jan 2024 10:33:40 -0700 Subject: [PATCH] Added app_start function to call alembic scripts (#37) Closes #36 --- src/main.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main.py b/src/main.py index 93bee0c5..ee7ddf14 100644 --- a/src/main.py +++ b/src/main.py @@ -1,8 +1,22 @@ +import os + from fastapi import FastAPI from routers import filing_router +from alembic.config import Config +from alembic import command + app = FastAPI() +@app.on_event("startup") +async def app_start(): + file_dir = os.path.dirname(os.path.realpath(__file__)) + alembic_cfg = Config(f"{file_dir}/../alembic.ini") + alembic_cfg.set_main_option("script_location", f"{file_dir}/../db_revisions") + alembic_cfg.set_main_option("prepend_sys_path", f"{file_dir}/../") + command.upgrade(alembic_cfg, "head") + + app.include_router(filing_router, prefix="/v1/filing")