Add Polaris FastAPI backend: models/schemas, pricing+scoring+order router, importer, Celery tasks, API routers, seed script

This commit is contained in:
drjones
2026-08-25 20:37:58 -07:00
parent 8573554bf9
commit 96b4fcaac9
32 changed files with 2211 additions and 0 deletions

30
backend/app/database.py Normal file
View File

@@ -0,0 +1,30 @@
"""Database engine/session wiring.
DATABASE_URL comes from env (set by docker-compose). On the CT host it falls
back to the local postgres port mapping using POSTGRES_PASSWORD from .env.
"""
import os
from dotenv import load_dotenv
from sqlalchemy import create_engine
from sqlalchemy.orm import declarative_base, sessionmaker
# /opt/polaris/.env exists on the CT host; harmless no-op elsewhere.
load_dotenv(os.getenv("POLARIS_ENV_FILE", "/opt/polaris/.env"), override=False)
DATABASE_URL = os.getenv(
"DATABASE_URL",
f"postgresql+psycopg2://reseller:{os.getenv('POSTGRES_PASSWORD', '')}@127.0.0.1:5432/reseller",
)
engine = create_engine(DATABASE_URL, pool_pre_ping=True, pool_size=5, max_overflow=10)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()