Running alembic migrations on startup
This commit is contained in:
@@ -11,6 +11,7 @@ from fastapi_jwt_auth.exceptions import AuthJWTException
|
||||
from pydantic import BaseModel
|
||||
|
||||
import src.settings as settings
|
||||
from src.database.alembic import run_migrations
|
||||
from src.database.database import init_db
|
||||
from src.exceptions.base_exception import BaseException
|
||||
from src.exceptions.exception_handlers import (auth_exception_handler,
|
||||
@@ -22,6 +23,10 @@ app = FastAPI(title="SignDataCollector", version="0.0.1")
|
||||
async def on_startup():
|
||||
await init_db()
|
||||
|
||||
# run migrations
|
||||
await run_migrations()
|
||||
|
||||
|
||||
|
||||
class AuthSettings(BaseModel):
|
||||
"""AuthSettings model"""
|
||||
|
||||
8
backend/src/database/alembic.py
Executable file
8
backend/src/database/alembic.py
Executable file
@@ -0,0 +1,8 @@
|
||||
from alembic import command
|
||||
from alembic.config import Config
|
||||
|
||||
|
||||
async def run_migrations():
|
||||
alembic_cfg = Config("alembic.ini")
|
||||
await command.upgrade(alembic_cfg, "head")
|
||||
|
||||
@@ -16,7 +16,6 @@ def _custom_json_serializer(*args, **kwargs) -> str:
|
||||
"""
|
||||
return json.dumps(*args, default=pydantic.json.pydantic_encoder, **kwargs)
|
||||
|
||||
print(settings.DB_USE_SQLITE)
|
||||
# check if the engine must be created for the tests -> in memory sqlite
|
||||
if settings.TEST_MODE:
|
||||
engine = create_async_engine(
|
||||
|
||||
Reference in New Issue
Block a user