Forecasting app: hybrid port to HNF stack
Python FastAPI ML backend kept intact; auth replaced with central hnf_session cookie verification. Frontend rebuilt on React 18 + TS + Vite with stack design system, Plotly charts retained. Shared Postgres via DATABASE_URL; schema applied on startup. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
75d2c1fa9d
103 changed files with 70316 additions and 0 deletions
42
backend/database.py
Normal file
42
backend/database.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
"""
|
||||
Database connection and session management
|
||||
"""
|
||||
import os
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
||||
from sqlalchemy.orm import sessionmaker, declarative_base
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
DATABASE_URL = os.getenv("DATABASE_URL", "postgresql://forecast:forecast_secret@localhost:5432/forecast")
|
||||
|
||||
# Convert to async URL
|
||||
ASYNC_DATABASE_URL = DATABASE_URL.replace("postgresql://", "postgresql+asyncpg://")
|
||||
|
||||
# Async engine for FastAPI
|
||||
async_engine = create_async_engine(ASYNC_DATABASE_URL, echo=False)
|
||||
AsyncSessionLocal = sessionmaker(
|
||||
async_engine, class_=AsyncSession, expire_on_commit=False
|
||||
)
|
||||
|
||||
# Sync engine for scheduler jobs and migrations
|
||||
sync_engine = create_engine(DATABASE_URL)
|
||||
SyncSessionLocal = sessionmaker(bind=sync_engine)
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
async def get_db():
|
||||
"""Dependency for FastAPI endpoints"""
|
||||
async with AsyncSessionLocal() as session:
|
||||
try:
|
||||
yield session
|
||||
finally:
|
||||
await session.close()
|
||||
|
||||
|
||||
def get_sync_db():
|
||||
"""Get sync session for scheduler jobs"""
|
||||
db = SyncSessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
Loading…
Add table
Add a link
Reference in a new issue