b3c3e2a3b2
- backend/app: FastAPI API wrapping the CAD skill modules - upload -> job -> poll -> model / BOM / artifacts -> geometry query - SQLite via SQLModel (Model, Job, BomRow, QueryLog) - ThreadPoolExecutor worker, serialized, with live stage updates - docker-compose.yml: dev server (mounts source, --reload) on :8000 - api-test.sh: end-to-end live validation script - requirements.txt: add fastapi, uvicorn, python-multipart, sqlmodel - external_diagram.py: port active-area detection OCC.Core -> OCP - .gitignore, PHASE1.md Validated live: MR16 round-trip passes (28 BOM rows, 12 artifacts, bounding-box query, xlsx download; active-area detection working). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
29 lines
929 B
Python
29 lines
929 B
Python
"""SQLite engine + session helpers.
|
|
|
|
SQLModel (SQLAlchemy + Pydantic) is used rather than Jason's usual Prisma — Prisma
|
|
is JS-first and its Python client is unofficial, whereas SQLModel is the FastAPI-
|
|
native ORM. SQLite stays the DB, single-file under the data volume.
|
|
"""
|
|
from sqlmodel import SQLModel, Session, create_engine
|
|
|
|
from .config import DATA_DIR, DB_PATH, MODELS_DIR
|
|
|
|
# check_same_thread=False: the worker thread shares the engine with request handlers.
|
|
engine = create_engine(
|
|
f"sqlite:///{DB_PATH}",
|
|
connect_args={"check_same_thread": False},
|
|
)
|
|
|
|
|
|
def init_db() -> None:
|
|
DATA_DIR.mkdir(parents=True, exist_ok=True)
|
|
MODELS_DIR.mkdir(parents=True, exist_ok=True)
|
|
# Import models so they register on SQLModel.metadata before create_all.
|
|
from . import models # noqa: F401
|
|
SQLModel.metadata.create_all(engine)
|
|
|
|
|
|
def get_session():
|
|
with Session(engine) as session:
|
|
yield session
|