Harden location db startup validation
This commit is contained in:
+13
@@ -8,6 +8,18 @@ from app import models # noqa: F401
|
||||
from app.api.routes import pages, status
|
||||
from app.api.routes.location import router as location_router
|
||||
from app.config import get_settings
|
||||
from scripts.location_db_adopt import LocationDatabaseAdoptionError, validate_location_runtime_db
|
||||
|
||||
|
||||
def ensure_location_db_ready() -> None:
|
||||
settings = get_settings()
|
||||
if settings.location_sqlite_path is None:
|
||||
return
|
||||
|
||||
try:
|
||||
validate_location_runtime_db(settings.location_database_url)
|
||||
except LocationDatabaseAdoptionError as exc:
|
||||
raise RuntimeError(str(exc)) from exc
|
||||
|
||||
|
||||
def ensure_runtime_dirs() -> None:
|
||||
@@ -20,6 +32,7 @@ def ensure_runtime_dirs() -> None:
|
||||
@asynccontextmanager
|
||||
async def lifespan(_: FastAPI):
|
||||
ensure_runtime_dirs()
|
||||
ensure_location_db_ready()
|
||||
yield
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user