feat: Add Alembic configuration and migration command to application startup
All checks were successful
Deploy to Production, build images and push to Gitea Registry / build_and_push (pull_request) Successful in 1m16s
All checks were successful
Deploy to Production, build images and push to Gitea Registry / build_and_push (pull_request) Successful in 1m16s
This commit is contained in:
parent
5a2b311a4f
commit
411c3c91b2
@ -47,6 +47,8 @@ WORKDIR /app
|
|||||||
COPY --chown=appuser:appuser app/ ./app/
|
COPY --chown=appuser:appuser app/ ./app/
|
||||||
COPY --chown=appuser:appuser *.py ./
|
COPY --chown=appuser:appuser *.py ./
|
||||||
COPY --chown=appuser:appuser requirements.txt ./
|
COPY --chown=appuser:appuser requirements.txt ./
|
||||||
|
COPY --chown=appuser:appuser alembic.ini ./
|
||||||
|
COPY --chown=appuser:appuser alembic/ ./alembic/
|
||||||
|
|
||||||
# Create logs directory
|
# Create logs directory
|
||||||
RUN mkdir -p /app/logs && chown -R appuser:appuser /app
|
RUN mkdir -p /app/logs && chown -R appuser:appuser /app
|
||||||
|
@ -9,6 +9,9 @@ from sentry_sdk.integrations.fastapi import FastApiIntegration
|
|||||||
from fastapi_users.authentication import JWTStrategy
|
from fastapi_users.authentication import JWTStrategy
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from jose import jwt, JWTError
|
from jose import jwt, JWTError
|
||||||
|
from alembic.config import Config
|
||||||
|
from alembic import command
|
||||||
|
import os
|
||||||
|
|
||||||
from app.api.api_router import api_router
|
from app.api.api_router import api_router
|
||||||
from app.config import settings
|
from app.config import settings
|
||||||
@ -216,8 +219,17 @@ async def read_root():
|
|||||||
async def startup_event():
|
async def startup_event():
|
||||||
"""Initialize services on startup."""
|
"""Initialize services on startup."""
|
||||||
logger.info(f"Application startup in {settings.ENVIRONMENT} environment...")
|
logger.info(f"Application startup in {settings.ENVIRONMENT} environment...")
|
||||||
# You might perform initial checks or warm-up here
|
|
||||||
# await database.engine.connect() # Example check (get_db handles sessions per request)
|
# Run database migrations
|
||||||
|
try:
|
||||||
|
logger.info("Running database migrations...")
|
||||||
|
alembic_cfg = Config("alembic.ini")
|
||||||
|
command.upgrade(alembic_cfg, "head")
|
||||||
|
logger.info("Database migrations completed successfully.")
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Failed to run database migrations: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
init_scheduler()
|
init_scheduler()
|
||||||
logger.info("Application startup complete.")
|
logger.info("Application startup complete.")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user