Compare commits

..

No commits in common. "530867bb160a4fb9b928f86c4b8705b7508716d4" and "de5f54f9701c04cd5a7e466390c35c124401e713" have entirely different histories.

2 changed files with 13 additions and 22 deletions

View File

@ -45,10 +45,10 @@ WORKDIR /app
# Copy only necessary application files (be selective)
COPY --chown=appuser:appuser app/ ./app/
COPY --chown=appuser:appuser alembic/ ./alembic/
COPY --chown=appuser:appuser alembic.ini ./
COPY --chown=appuser:appuser *.py ./
COPY --chown=appuser:appuser requirements.txt ./
COPY --chown=appuser:appuser alembic.ini ./
COPY --chown=appuser:appuser alembic/ ./alembic/
# Create logs directory
RUN mkdir -p /app/logs && chown -R appuser:appuser /app

View File

@ -9,7 +9,6 @@ from sentry_sdk.integrations.fastapi import FastApiIntegration
from fastapi_users.authentication import JWTStrategy
from pydantic import BaseModel
from jose import jwt, JWTError
from sqlalchemy.ext.asyncio import AsyncEngine
from alembic.config import Config
from alembic import command
import os
@ -214,33 +213,25 @@ async def read_root():
}
# --- End Root Endpoint ---
async def run_migrations():
"""Run database migrations."""
try:
logger.info("Running database migrations...")
# Get the path to the alembic.ini file
alembic_ini_path = os.path.join(os.path.dirname(__file__), '..', 'alembic.ini')
# Create Alembic configuration
alembic_cfg = Config(alembic_ini_path)
# Run the migration
command.upgrade(alembic_cfg, "head")
logger.info("Database migrations completed successfully.")
except Exception as e:
logger.error(f"Error running migrations: {e}")
raise
# --- Application Startup/Shutdown Events (Optional) ---
@app.on_event("startup")
async def startup_event():
"""Initialize services on startup."""
logger.info(f"Application startup in {settings.ENVIRONMENT} environment...")
# Run database migrations
await run_migrations()
try:
logger.info("Running database migrations...")
alembic_cfg = Config()
alembic_cfg.set_main_option("script_location", "alembic")
alembic_cfg.set_main_option("sqlalchemy.url", settings.DATABASE_URL)
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
# Initialize scheduler
init_scheduler()
logger.info("Application startup complete.")