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
|
from pydantic import BaseModel
|
||||||
|
|
||||||
import src.settings as settings
|
import src.settings as settings
|
||||||
|
from src.database.alembic import run_migrations
|
||||||
from src.database.database import init_db
|
from src.database.database import init_db
|
||||||
from src.exceptions.base_exception import BaseException
|
from src.exceptions.base_exception import BaseException
|
||||||
from src.exceptions.exception_handlers import (auth_exception_handler,
|
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():
|
async def on_startup():
|
||||||
await init_db()
|
await init_db()
|
||||||
|
|
||||||
|
# run migrations
|
||||||
|
await run_migrations()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AuthSettings(BaseModel):
|
class AuthSettings(BaseModel):
|
||||||
"""AuthSettings model"""
|
"""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)
|
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
|
# check if the engine must be created for the tests -> in memory sqlite
|
||||||
if settings.TEST_MODE:
|
if settings.TEST_MODE:
|
||||||
engine = create_async_engine(
|
engine = create_async_engine(
|
||||||
|
|||||||
Reference in New Issue
Block a user