From b29823a6b13c5c62f244aeb87b92d9698ac4b89c Mon Sep 17 00:00:00 2001 From: itqop Date: Wed, 31 Dec 2025 01:52:47 +0300 Subject: [PATCH] add auto migrations --- backend/src/app/infra/database.py | 7 ++++++- backend/src/app/main.py | 4 +--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/backend/src/app/infra/database.py b/backend/src/app/infra/database.py index b8af4b4..a0bb604 100644 --- a/backend/src/app/infra/database.py +++ b/backend/src/app/infra/database.py @@ -51,6 +51,11 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]: async def init_db() -> None: - """Initialize database tables.""" + """ + Initialize database tables using create_all(). + + WARNING: Only for testing! In production/dev, use Alembic migrations. + Using both create_all() and Alembic creates inconsistent state. + """ async with engine.begin() as conn: await conn.run_sync(Base.metadata.create_all) diff --git a/backend/src/app/main.py b/backend/src/app/main.py index 1aef244..39e59f3 100644 --- a/backend/src/app/main.py +++ b/backend/src/app/main.py @@ -7,7 +7,6 @@ from fastapi.middleware.cors import CORSMiddleware from app.api.v1 import assets, auth, batch, folders, shares, uploads from app.infra.config import get_settings -from app.infra.database import init_db settings = get_settings() @@ -15,8 +14,7 @@ settings = get_settings() @asynccontextmanager async def lifespan(app: FastAPI): """Application lifespan handler.""" - # Startup - await init_db() + # Startup - schema managed by Alembic migrations in Dockerfile yield # Shutdown pass