FastAPI backend for personal health and skincare data with MCP export. Includes SQLModel models for products, inventory, medications, lab results, routines, and skin condition snapshots. Pytest suite with 111 tests running on SQLite in-memory (no PostgreSQL required). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
21 lines
597 B
Python
21 lines
597 B
Python
import os
|
|
|
|
from sqlmodel import Session, SQLModel, create_engine
|
|
|
|
DATABASE_URL = os.environ.get(
|
|
"DATABASE_URL", "postgresql+psycopg://localhost/innercontext"
|
|
)
|
|
connect_args = {"check_same_thread": False} if DATABASE_URL.startswith("sqlite") else {}
|
|
engine = create_engine(DATABASE_URL, pool_pre_ping=True, connect_args=connect_args)
|
|
|
|
|
|
def get_session():
|
|
with Session(engine) as session:
|
|
yield session
|
|
|
|
|
|
def create_db_and_tables():
|
|
# Import all models so SQLModel.metadata knows about them
|
|
import innercontext.models # noqa: F401
|
|
|
|
SQLModel.metadata.create_all(engine)
|