add auto migrations
This commit is contained in:
parent
e263fbc98a
commit
b29823a6b1
|
|
@ -51,6 +51,11 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
||||||
|
|
||||||
|
|
||||||
async def init_db() -> 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:
|
async with engine.begin() as conn:
|
||||||
await conn.run_sync(Base.metadata.create_all)
|
await conn.run_sync(Base.metadata.create_all)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
from app.api.v1 import assets, auth, batch, folders, shares, uploads
|
from app.api.v1 import assets, auth, batch, folders, shares, uploads
|
||||||
from app.infra.config import get_settings
|
from app.infra.config import get_settings
|
||||||
from app.infra.database import init_db
|
|
||||||
|
|
||||||
settings = get_settings()
|
settings = get_settings()
|
||||||
|
|
||||||
|
|
@ -15,8 +14,7 @@ settings = get_settings()
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
"""Application lifespan handler."""
|
"""Application lifespan handler."""
|
||||||
# Startup
|
# Startup - schema managed by Alembic migrations in Dockerfile
|
||||||
await init_db()
|
|
||||||
yield
|
yield
|
||||||
# Shutdown
|
# Shutdown
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue