File size: 1,776 Bytes
5d1a8d2 cfcea40 5d1a8d2 cfcea40 5d1a8d2 cfcea40 5d1a8d2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | """
Main FastAPI Application
ββββββββββββββββββββββββ
Ties everything together: API + Admin + MCP + Backup scheduler
Sources:
- FastAPI: https://fastapi.tiangolo.com/
"""
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from contextlib import asynccontextmanager
import asyncio
import logging
from app.database import init_db
from app.backup import scheduled_backup_task
from app.admin.router import router as admin_router
from app.api.routes import router as api_router
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
"""
Startup: init DB + start backup scheduler
Shutdown: cleanup
"""
# ββ STARTUP ββ
logger.info("π Initializing database...")
init_db()
logger.info("β
Database ready")
# Start background backup scheduler
backup_task = asyncio.create_task(scheduled_backup_task())
logger.info("β° Backup scheduler started (every 30 min)")
yield
# ββ SHUTDOWN ββ
backup_task.cancel()
logger.info("π Shutting down")
app = FastAPI(
title="SQLite DBaaS - Admin Console",
description="SQLite + Litestream + HF Bucket powered database service",
version="1.0.0",
lifespan=lifespan,
)
# ββ Mount routes ββ
app.include_router(admin_router)
app.include_router(api_router)
# ββ Mount static files ββ
app.mount("/static", StaticFiles(directory="static"), name="static")
@app.get("/")
async def root():
return {
"status": "running",
"service": "SQLite DBaaS",
"admin": "/admin/login",
"docs": "/docs",
"health": "/admin/api/health",
}
|