This commit is contained in:
Mikan
2026-06-21 01:02:25 +03:00
parent 49ff467d3a
commit c21a13d2a3
4 changed files with 37 additions and 3 deletions

View File

@@ -35,6 +35,20 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
_logger.info("app_starting", version=__version__, debug=cfg.debug)
# Startup -------------------------------------------------------------
# Step 0: Create all DB tables (idempotent — equivalent to alembic upgrade head).
# This must run BEFORE any settings query, otherwise seed_default_settings
# crashes with "relation 'settings' does not exist".
from app.db import get_engine
from app.migrations.versions._001_initial_schema import create_all_tables
try:
engine = get_engine()
await create_all_tables(engine)
_logger.info("db_tables_ready")
except Exception as e: # noqa: BLE001
_logger.error("db_tables_create_failed", error=str(e))
# Continue anyway — /api/health will reflect the broken state
sm = get_sessionmaker()
try:
async with sm() as session:
@@ -61,12 +75,21 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
print(f"===========================\n")
else:
_logger.info("admins_present", count=admins_count)
# 4) Init Qdrant collections
# 4) seed builtin presets (idempotent)
from app.migrations.seed import seed_builtin_presets
try:
await seed_builtin_presets(session)
_logger.info("presets_seeded")
except Exception as e: # noqa: BLE001
_logger.warning("presets_seed_failed", error=str(e))
# 5) Init Qdrant collections
from app.core.settings_service import get_setting
dim = int(await get_setting(session, "embeddings.dimension") or 256)
try:
await init_qdrant_collections(dim)
_logger.info("qdrant_collections_ready", dimension=dim)
except Exception as e: # noqa: BLE001
_logger.warning("qdrant_init_failed", error=str(e))
except Exception as e: # noqa: BLE001