INNER CODE UNIT · Python
lifespan
LeDat98/NexusRAG · backend/app/main.py:25
async def lifespan(app: FastAPI):
logger.info("Starting NexusRAG API...")
import os
auto_create = os.environ.get("AUTO_CREATE_TABLES", "true").lower() == "true"
if auto_create:
async with engine.begin() as conn:
# Check if tables already exist (e.g., alembic_version)
result = await conn.execute(
text("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'public' AND table_name = 'alembic_version');")
)
is_initialized = result.scalar()
if not is_initialized:
schema_path = os.path.join(os.path.dirname(__file__), "schema.sql")
if os.path.exists(schema_path):
with open(schema_path, "r", encoding="utf-8") as f:
schema_sql = f.read()