endpoints - add SQLAlchemy models for RSVPS and singleton invitation configuration - implement phone number normalization (10d Colombia standard) and duplicate detection - add Authelia Remote-User security guard on all admin endpoints - use typing.Annotated for FastAPI dependencies and date.fromisoformat - add CSV export for RSVP responses - add SPA catch-all mount under /birthday/ - add linting and static check configuration
44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
import os
|
|
from collections.abc import Generator
|
|
|
|
from sqlalchemy import create_engine, event
|
|
from sqlalchemy.orm import DeclarativeBase, Session, sessionmaker
|
|
|
|
from .config import settings
|
|
|
|
# Ensure data directory exists if a local relative file path is used
|
|
if settings.DATABASE_URL.startswith("sqlite:///./data/"):
|
|
os.makedirs("./data", exist_ok=True)
|
|
|
|
connect_args = {}
|
|
if settings.DATABASE_URL.startswith("sqlite"):
|
|
connect_args["check_same_thread"] = False
|
|
|
|
engine = create_engine(
|
|
settings.DATABASE_URL,
|
|
connect_args=connect_args,
|
|
)
|
|
|
|
|
|
@event.listens_for(engine, "connect")
|
|
def set_sqlite_pragma(dbapi_connection, connection_record):
|
|
if settings.DATABASE_URL.startswith("sqlite"):
|
|
cursor = dbapi_connection.cursor()
|
|
cursor.execute("PRAGMA journal_mode=WAL;")
|
|
cursor.close()
|
|
|
|
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
|
|
|
|
class Base(DeclarativeBase):
|
|
pass
|
|
|
|
|
|
def get_db() -> Generator[Session, None, None]:
|
|
db = SessionLocal()
|
|
try:
|
|
yield db
|
|
finally:
|
|
db.close()
|