- API: POST /api/compact (optional body {"files": [...]})
- CLI: python main.py compact [--db FILE]
- Local path: rename → CompactDatabase(bak→src) → delete bak (zero copy)
- UNC path: copy to local temp → compact → copy back (avoids DAO segfault)
- Uses DAO DBEngine.CompactDatabase via pywin32 COM
- new dep: pywin32>=306
Co-Authored-By: Claude <noreply@anthropic.com>
36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
"""FastAPI application factory.
|
|
|
|
``create_app(state, cfg)`` builds the app, binds the shared singletons (the
|
|
process-wide :class:`ServiceState` and :class:`SyncConfig`) into the dependency
|
|
graph, and mounts route modules. New operational endpoints are added by
|
|
creating a ``routes/<name>.py`` with an ``APIRouter`` and ``include_router``-
|
|
ing it here.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from ..config import SyncConfig
|
|
from ..health import ServiceState
|
|
from . import deps
|
|
from .routes import compact as compact_routes
|
|
from .routes import health as health_routes
|
|
|
|
|
|
def create_app(state: ServiceState, cfg: SyncConfig) -> FastAPI:
|
|
"""Build the FastAPI app with health state/config bound for injection."""
|
|
app = FastAPI(
|
|
title="DataMacroSync",
|
|
description="Access -> SQL Server incremental sync operational API",
|
|
version="1.0.0",
|
|
# Keep all auto-generated docs under /api alongside the operational
|
|
# routes, so the whole HTTP surface shares one prefix.
|
|
docs_url="/api/docs",
|
|
redoc_url="/api/redoc",
|
|
openapi_url="/api/openapi.json",
|
|
)
|
|
deps.bind(state, cfg)
|
|
app.include_router(compact_routes.router)
|
|
app.include_router(health_routes.router)
|
|
return app
|