fix: auto-create DB tables at startup to fix UndefinedTableError on first boot
Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> Agent-Logs-Url: https://github.com/christianlouis/pop_puller_to_gmail/sessions/148f7d4a-586e-4c3a-9d56-187b41daf277
This commit is contained in:
@@ -29,6 +29,21 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
||||
logger.info(f"Debug mode: {settings.DEBUG}")
|
||||
logger.info("API documentation: /api/docs")
|
||||
|
||||
# Ensure all database tables exist (idempotent; safe to run on every startup)
|
||||
try:
|
||||
from app.core.database import engine, Base
|
||||
import app.models.database_models # noqa: F401 - register all ORM models
|
||||
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
logger.info("Database tables verified/created")
|
||||
except Exception as exc:
|
||||
logger.error(
|
||||
"Could not create database tables: %s — API requests requiring DB will fail",
|
||||
exc,
|
||||
exc_info=True,
|
||||
)
|
||||
|
||||
# Seed default database-backed settings (no-op if they already exist)
|
||||
try:
|
||||
from app.core.database import async_session_maker
|
||||
|
||||
Reference in New Issue
Block a user